threadpool

Does Java have an indexable multi-queue thread pool?

馋奶兔 提交于 2019-12-01 17:46:09
Is there a Java class such that: Executable tasks can be added via an id, where all tasks with the same id are guaranteed to never run concurrently The number of threads can be limited to a fixed amount A naive solution of a Map would easily solve (1), but it would be difficult to manage (2). Similarly, all thread pooling classes that I know of will pull from a single queue, meaning (1) is not guaranteed. Solutions involving external libraries are welcome. If you don't find something that does this out of the box, it shouldn't be hard to roll your own. One thing you could do is to wrap each

C#, IAsyncResult and the thread pool

﹥>﹥吖頭↗ 提交于 2019-12-01 17:44:53
问题 I use the Action<object>.BeginInvoke() method, does this use the thread pool or not? I have the following C# code: List<FileHash> hashList1 = hashList.Where((x, ind) => ind % 2 == 0).ToList(); List<FileHash> hashList2 = hashList.Where((x, ind) => ind % 2 == 1).ToList(); Action<object> oddWork = CalcHash; Action<object> evenWork = CalcHash; IAsyncResult evenHandle = evenWork.BeginInvoke(hashList1, null, null); IAsyncResult oddHandle = oddWork.BeginInvoke(hashList2, null, null); evenWork

MonoTouch - Threading

廉价感情. 提交于 2019-12-01 16:43:46
问题 A common task is to do something in the background thread, then when done, pass the results to the UI thread and inform the user. I understand there are two common ways: I can use the TPL: var context = TaskScheduler.FromCurrentSynchronizationContext (); Task.Factory.StartNew (() => { DoSomeExpensiveTask(); return "Hi Mom"; }).ContinueWith (t => { DoSomethingInUI(t.Result); }, context); Or the Older ThreadPool: ThreadPool.QueueUserWorkItem ((e) => { DoSomeExpensiveTask(); this

Thread Pool and .IsBackground in .NET

痴心易碎 提交于 2019-12-01 16:29:25
MSDN, as well as many other sources, claim that worker threads in the thread pool are always background. "Thread pool threads are background threads." (MSDN) "Pooled threads are always background threads." (Threading in C#, Joseph Albahari) I can easily make the worker thread non-background by setting Thread.CurrentThread.IsBackground = false; And the application will be waiting until the thread finishes. What's wrong with that? When does the thread finish? When your method ends? I highly doubt that's the case. The whole point of the thread pool is that once your thread is finished, it gets

Does Java have an indexable multi-queue thread pool?

一曲冷凌霜 提交于 2019-12-01 15:54:20
问题 Is there a Java class such that: Executable tasks can be added via an id, where all tasks with the same id are guaranteed to never run concurrently The number of threads can be limited to a fixed amount A naive solution of a Map would easily solve (1), but it would be difficult to manage (2). Similarly, all thread pooling classes that I know of will pull from a single queue, meaning (1) is not guaranteed. Solutions involving external libraries are welcome. 回答1: If you don't find something

background worker(threadpool) in asp.net

假如想象 提交于 2019-12-01 14:02:27
I have a asp.net webform which writes about 25-30 items(has info required when user makes follow up request from the form) into a custom cache. Currently all this happens synchronously on the main thread. But at higher loads addcache is becoming a bottleneck. How can i run this task in the background without consuming threads from the asp.net worker process thread pool. Jupaol Alternatives: Completely async: Call the server code using AJAX from the client, and add code to monitor the process of the call I just added an answer related to this process: https://stackoverflow.com/a/11524718

background worker(threadpool) in asp.net

一个人想着一个人 提交于 2019-12-01 12:33:13
问题 I have a asp.net webform which writes about 25-30 items(has info required when user makes follow up request from the form) into a custom cache. Currently all this happens synchronously on the main thread. But at higher loads addcache is becoming a bottleneck. How can i run this task in the background without consuming threads from the asp.net worker process thread pool. 回答1: Alternatives: Completely async: Call the server code using AJAX from the client, and add code to monitor the process of

Why does the following executor service java Thread program doesn't shut down?

情到浓时终转凉″ 提交于 2019-12-01 12:11:54
问题 import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue

java schedule a callable at pseudo 'fixed' rate (bell curve distribution for example)

点点圈 提交于 2019-12-01 12:09:41
Currently I have a ScheduledThreadPoolExecutor which can execute a callable at a fixed rate. scheduledThreadPoolExecutor.scheduleAtFixedRate(callable, delay, waitNano, TimeUnit.NANOSECONDS); My team wants to add some randomess into the waitNano. Currently it is 1000. But we want the wait second to be 900, 1100, 800, 1200, for example. The average wait time is still 1000 but the wait second is randomly distributed, (for example like a Bell curve). I am wondering is this functionality already in java? If I have to write my own "scheduler" which has this random-waiting behavior, what do you guys

Multithreading best practices : constraining tasks newFixedThreadPool

ε祈祈猫儿з 提交于 2019-12-01 11:07:37
I want to launch a lot of tasks to run on a database of +-42Mio records. I want to run this in batches of 5000 records/time (results in 850 tasks). I also want to limit the number of threads (to 16) java starts to do this for me and I am using the current code to accomplish this task: ExecutorService executorService = Executors.newFixedThreadPool(16); for (int j = 1; j < 900 + 1; j++) { int start = (j - 1) * 5000; int stop = (j) * 5000- 1; FetcherRunner runner = new FetcherRunner(routes, start, stop); executorService.submit(runner); Thread t = new Thread(runner); threadsList.add(t); t.start();