threadpool

Java set a callback from ExecutorService

故事扮演 提交于 2019-11-30 11:45:37
I have a fixedThreadPool that I am using to run a bunch of worker threads to achieve parallel execution of a task with many components. When all threads have finished, I retrieve their results (which are quite large) using a method (getResult) and write them to a file. Ultimately, to save memory and be able to see intermediate results, I'd like each thread to write its result to the file as soon as it finishes execution and then free its memory. Ordinarily, I'd add code to that effect to the end of the run() method. However, certain other objects in this class also calls these threads, but DO

how do I use key word arguments with python multiprocessing pool apply_async

梦想的初衷 提交于 2019-11-30 11:35:56
I'm trying to get to grips with pythons multiprocessing module, specifically the apply_async method of Pool . I'm trying to call a function with arguments and keyword arguments. If I call the function without kwargs it's fine but when I try to add in a keyword argument I get: TypeError: apply_async() got an unexpected keyword argument 'arg2' Below is the test code that I'm running #!/usr/bin/env python import multiprocessing from time import sleep def test(arg1, arg2=1, arg3=2): sleep(5) if __name__ == '__main__': pool = multiprocessing.Pool() for t in range(1000): pool.apply_async(test, t,

How to interpret a Java thread stack?

若如初见. 提交于 2019-11-30 11:05:26
问题 In line with this question: How to get stack trace of a thread I am wondering if anyone could point to information about interpreting Java thread stacks extracted with jstack . My situation is that I've got a Java EE 5 application running on GlassFish v2.1.1 that hangs periodically (at least 2 -3 times a day).To get it running again I have to kill the Glassfish process and start the domain again. The application usually gets slower and slower responding until it finally hangs completely. Once

c# Threadpool - limit number of threads

本秂侑毒 提交于 2019-11-30 11:03:51
问题 I am developing a console app. I want to use a Threadpool to perform web downloads. Here is some fake code. for (int loop=0; loop< 100; loop++) { ThreadPool.QueueUserWorkItem(new WaitCallback(GetPage), pageList[loop]); } snip private static void GetPage(object o) { //get the page } How do I prevent my code from starting more than two (or ten, or whatever) simultaneous threads? I have tried ThreadPool.SetMaxThreads(1, 0); ThreadPool.SetMinThreads(1, 0); But they seem to have no impact. 回答1: I

Connection pool and File handles

情到浓时终转凉″ 提交于 2019-11-30 10:11:53
We use Retrofit/OkHttp3 for all network traffic from our Android application. So far everything seems to run quite smoothly. However, we have now occasionally had our app/process run out of file handles. Android allows for a max of 1024 file handles per process OkHttp will create a new thread for each async call Each thread created this way will (from our observation) be responsible for 3 new file handles (2 pipes and one socket). We were able to debug this exactly, where each dispached async call using .enqueue() will lead to an increase of open file handles of 3. The problem is, that the

Limit Threads count

我只是一个虾纸丫 提交于 2019-11-30 10:01:22
I have a List with items that I want to download. I use a for Loop to iterate the list. For each item in this List I start a new Thread that references the item. My Problem is that I want limit the maxDownload at the same time. for (int i = downloadList.Count - 1; i >= 0; i--) { downloadItem item = downloadList[i]; if (item.Status != 1 && item.Status != 2) { ThreadStart starter = delegate { this.DownloadItem(ref item); }; Thread t = new Thread(starter); t.IsBackground = true; t.Name = item.Name; t.Priority = ThreadPriority.Normal; t.Start(); } } I read something about the ThreadPool, but then

AsyncTask inside a loop

回眸只為那壹抹淺笑 提交于 2019-11-30 09:47:52
问题 Basically I want start a few threads which execute serially one after the another. I'm using Thread.join() for it. But the application kinds of hangs out and goes in ANR state. I want to know that putting an AsyncTask inside a loop will execute all the tasks serially one after the another or will they be executing parallelly??? for(String s : list) { new asynctask(s).execute(); } 回答1: Basically I want start a few threads which execute serially one after the another. The thing immediately

Why tasks in Threadpool are not executed following FIFO, Java

三世轮回 提交于 2019-11-30 09:41:35
问题 I know if queue is full the new task will be executed by a newly created thread in priority according to How to guarantee FIFO execution order in a ThreadPoolExecutor But I have following test code snippets which min core size = max core size. public class ThreadPoolFifoTest { public static void main(String[] args) throws InterruptedException { Executor ex = Executors.newFixedThreadPool(10); final List<Integer> l = new LinkedList<Integer>(); final ReentrantLock lock = new ReentrantLock(true);

java Callable FutureTask Excecuter: How to listen to finished task

爱⌒轻易说出口 提交于 2019-11-30 09:07:33
I'm quite new to executer services. Liked doing everything myself, but I think it's time to trust these services. I want to hand by Executer a Runnable . The executer wraps that in a FutureTask and hands it back to me. Now I call poll the done() method. But I would like to be notified when then done() method would return true. There is a get() method that blocks until the Runnable has finished, but then I would need a extra thread for every job, just to see when it's finished. Can I hand my executer some extra Callable to get notified about the task finishing? What's the way to go here? I

Directed Graph Processing in Java

折月煮酒 提交于 2019-11-30 08:31:03
问题 I am looking to implement a Java application that will compute a set of tasks to execute. The tasks will have dependencies on each other, forming a directed graph. Is there an existing SDK or algorithm (preferably in Java) out there that will help me: Define the graph of tasks Ensure there are no cyclic dependencies in the graph Execute the tasks in the graph using a thread pool Step 3 is the most important part. I need to execute the tasks in a parallel fashion for maximum performance yet