threadpool

Multithreaded job queue manager

↘锁芯ラ 提交于 2019-11-29 19:47:00
I need to manage CPU-heavy multitaskable jobs in an interactive application. Just as background, my specific application is an engineering design interface. As a user tweaks different parameters and options to a model, multiple simulations are run in the background and results displayed as they complete, likely even as the user is still editing values. Since the multiple simulations take variable time (some are milliseconds, some take 5 seconds, some take 10 minutes), it's basically a matter of getting feedback displayed as fast as possible, but often aborting jobs that started previously but

Doubts in the code of Thread Pool implementation

点点圈 提交于 2019-11-29 17:11:32
After spending lots of time with threadpool concepts and by reading different codes on numbers of blogs and posting questions on Stackoverflow.com, now I got clear image of this concept. But in the meanwhile, I found some doubts in code. When pool.assign(new TestWorkerThread()); executes in TestThreadPool Class, it calls done.workerBegin(); method that is in Done Class , where it increments _activeThreads variable. But what I thinks is, LOGICALLY that is not correct because if number of threads are less(in this case 2) than number of tasks (given in TestThreadPool Class )(in this case 5), it

System.OutOfMemoryException' was thrown - WebClient.DownloadStringAsynch()

旧巷老猫 提交于 2019-11-29 17:03:09
I'm writing a poor mans load tester and I thought I was managing my resources correctly (thread pool) but when I run the following code I get an OutOfMemoryException on my call to WebClient.DownloadStringAsynch. Using .net4.0 but could move to 4.5. ASKs: What is the fix? How could I use HttpWebRequest and send that asynch as an alternative to webclient? What about using .net 4.5 using await (any difference with how .net4 manages threads with asynch calls? static void Main(string[] args) { System.Net.ServicePointManager.DefaultConnectionLimit = 200; while (true) { for (int i = 0; i < 100; i++)

AsyncTask inside a loop

你离开我真会死。 提交于 2019-11-29 16:58:08
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(); } Basically I want start a few threads which execute serially one after the another. The thing immediately comes to my mind after reading this statement is You should consider using IntentService Rather than Creating

How to implement an ExecutorService to execute tasks on a rotation-basis?

守給你的承諾、 提交于 2019-11-29 14:54:46
问题 I'm using java.util.concurrent.ExecutorService with fixed thread pool to execute list of tasks. My list of tasks will typically be around 80 - 150 and I've limited the number of threads running at any time to 10 as shown below: ExecutorService threadPoolService = Executors.newFixedThreadPool(10); for ( Runnable task : myTasks ) { threadPoolService.submit(task); } My use case demands that even the completed task should be re-submitted again to the ExecutorService but it should be executed

Does changing the culture of a threadpool thread affect it when it gets returned back to the pool?

谁说我不能喝 提交于 2019-11-29 14:05:00
If I set the CurrentCulture of a thread pool thread, what happens when the thread finishes execution and gets returned back to the thread pool? Does it get its CurrentCulture reset back to the default (whatever that may mean), or will it retain the culture I have set on it? I'm hoping that the framework resets the thread to a default state to guard against this, but cannot find any documentation to this effect. The closest I have found is from the MSDN docs for ThreadPool : When the thread pool reuses a thread, it does not clear the data in thread local storage or in fields that are marked

Alternative to Thread.Sleep in C#?

我的梦境 提交于 2019-11-29 13:56:23
I have a code which when run, it executes series of lines in sequence. I would like to add a pause in between. Currently, I have it like this //do work Thread.Sleep(10800000); //do work This however freezes the software, and I think it's because sleep time is way too long. I searched online and I found another work around called Timer. Can someone show me a sample code for Timer which works just like Thread.sleep? Thank you in advance. Edit : I need the software to wait for 3 hours before proceeding with rest of the code execution. This software is meant to communicate with machines, and I

CompletableFuture allof(..).join() vs CompletableFuture.join()

你说的曾经没有我的故事 提交于 2019-11-29 12:54:09
I am currently using CompletableFuture supplyAsync() method for submitting some tasks to common thread pool. Here is what code snippet looks like: final List<CompletableFuture<List<Test>>> completableFutures = resolvers.stream() .map(resolver -> supplyAsync(() -> task.doWork())) .collect(toList()); CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[completableFutures.size()])).join(); final List<Test> tests = new ArrayList<>(); completableFutures.stream() .map(completableFuture -> completableFuture.getNow()) .forEach(tests::addAll); I would like to know how below differs

Reasonable number of threads for thread pool running web service requests

时光毁灭记忆、已成空白 提交于 2019-11-29 11:24:37
问题 When creating an FixedThreadPool Executor object in Java you need to pass an argument describing the number of threads that the Executor can execute concurrently. I'm building a service class that's responsibility is to process a large collections of phone numbers. For each phone number I need to execute web service (that's my bottleneck) and then save response in a hashmap. To make this bottleneck less harmful to the performance of my service I've decided to create Worker class which fetches

Task continuation parallel execution with async/await

北城以北 提交于 2019-11-29 10:23:32
In the context of a console application making use of async/await constructs, I would like to know if it's possible for "continuations" to run in parallel on multiple threads on different CPUs. I think this is the case, as continuations are posted on the default task scheduler (no SynchronizationContext in console app), which is the thread pool. I know that async/await construct do not construct any additional thread. Still there should be at least one thread constructed per CPU by the thread pool, and therefore if continuations are posted on the thread pool, it could schedule task