threadpool

Can somebody explain this odd behavior when working with ThreadPool?

若如初见. 提交于 2019-11-27 16:13:52
The Code using System; using System.Threading; public delegate void LoadingProgressCallback(double PercentComplete,string ItemName); public delegate void LoadCompleteCallback(int ItemID, string ItemName); public static class Program { public static void Main(string[] args) { LoadTest loadTest = new LoadTest(); loadTest.LoadItems(args); } } public class LoadTest { ManualResetEvent resetEvent; int numThreads = 0; public LoadTest() {} public void LoadItems(string[] Items) { numThreads = 0; resetEvent = new ManualResetEvent(false); foreach(string item in Items) { Console.WriteLine("Adding {0} to

Dynamic Thread Pool

牧云@^-^@ 提交于 2019-11-27 15:44:44
I have a long running process that listens to events and do some intense processing. Currently I use Executors.newFixedThreadPool(x) to throttle the number of jobs that runs concurrently, but depending of the time of the day, and other various factors, I would like to be able to dynamically increase or decrease the number of concurrent threads. If I decrease the number of concurrent threads, I want the current running jobs to finish nicely. Is there a Java library that let me control and dynamically increase or decrease the number of concurrent threads running in a Thread Pool ? (The class

what's the proper way to use a ThreadPool?

狂风中的少年 提交于 2019-11-27 14:29:27
问题 If my understanding of the way the ThreadPool works is correct, one of its purposes is to limit the number of worker threads within a process that can be created at a given time. For example, if you set MaxThreads to 5 and then call QueueUserWorkItem 30 times, 30 requests will be made to the ThreadPool, but only 5 of those requests will be serviced by a new thread, while the other 25 requests will be added to the queue and serviced one at time as previous requests complete and existing

Thread/threadpool or backgroundworker

蓝咒 提交于 2019-11-27 13:49:18
I would like to know what to use for tasks that need alot of performance. Backgroundworker , Thread or ThreadPool ? I've been working with Threads so far, but I need to improve speed of my applications. BackgroundWorker is the same thing as a thread pool thread. It adds the ability to run events on the UI thread. Very useful to show progress and to update the UI with the result. So its typical usage is to prevent the UI from freezing when works needs to be done. Performance is not the first goal, running code asynchronously is. This pattern is also ably extended in later .NET versions by the

WaitAll for multiple handles on a STA thread is not supported

孤人 提交于 2019-11-27 12:34:29
Why do I get this error message? "WaitAll for multiple handles on a STA thread is not supported." Should I use [MTAThreadAttribute] attribut? Update: Dosn't work with WPF applications! Note: It error is at line WaitHandle.WaitAll(doneEvents); I'm using a standard WPF project . private void Search() { const int CPUs = 2; var doneEvents = new ManualResetEvent[CPUs]; // Configure and launch threads using ThreadPool: for (int i = 0; i < CPUs; i++) { doneEvents[i] = new ManualResetEvent(false); var f = new Indexer(Paths[i], doneEvents[i]); ThreadPool.QueueUserWorkItem(f.WaitCallBack, i); } // Wait

How to reuse threads in .NET 3.5

让人想犯罪 __ 提交于 2019-11-27 12:33:35
问题 I have a subroutine that processes large blocks of information. In order to make use of the entire CPU, it divides the work up into separate threads. After all threads have completed, it finishes. I read that creating and destroying threads uses lots of overhead, so I tried using the threadpool, but that actually runs slower than creating my own threads. How can I create my own threads when the program runs and then keep reusing them? I've seen some people say it can't be done, but the

Wait for QueueUserWorkItem to Complete

拜拜、爱过 提交于 2019-11-27 12:09:22
If I add jobs to the thread pool with QueueUserWorkItem ... how do I keep my program from going forward until all jobs are completed? I know I could add some logic to keep the app from running until all jobs are completed, but I want to know if there is something like Thread.Join() or if there's any way to retrieve each thread that is being assigned a job. You could use events to sync. Like this: private static ManualResetEvent resetEvent = new ManualResetEvent(false); public static void Main() { ThreadPool.QueueUserWorkItem(arg => DoWork()); resetEvent.WaitOne(); } public static void DoWork()

What determines the number of threads a Java ForkJoinPool creates?

守給你的承諾、 提交于 2019-11-27 11:46:47
As far as I had understood ForkJoinPool , that pool creates a fixed number of threads (default: number of cores) and will never create more threads (unless the application indicates a need for those by using managedBlock ). However, using ForkJoinPool.getPoolSize() I discovered that in a program that creates 30,000 tasks ( RecursiveAction ), the ForkJoinPool executing those tasks uses 700 threads on average (threads counted each time a task is created). The tasks don't do I/O, but pure computation; the only inter-task synchronization is calling ForkJoinTask.join() and accessing AtomicBoolean s

Accessing scoped proxy beans within Threads of

半世苍凉 提交于 2019-11-27 11:30:13
I have a web application running in tomcat where I'm using a ThreadPool (Java 5 ExecutorService) to run IO intensive operations in parallel to improve performance. I would like to have some of the beans used within each pooled thread be in the request scope, but the Threads in the ThreadPool do not have access to the spring context and get a proxy failure. Any ideas on how to make the spring context available to the threads in the ThreadPool to resolve the proxy failures? I'm guessing there must be a way to register/unregister each thread in the ThreadPool with spring for each task, but haven

tomcat 6 thread pool for asynchronous processing

陌路散爱 提交于 2019-11-27 11:22:46
问题 Short question: Within a Tomcat 6 app - how can I run a (separate) thread-pool? What is the best solution for running a thread pool? Long question: I have a simple need here; Poll a database for some data, while allowing web clients wait for an answer (long poll connections). When this data is available at the database I'll send a reply to the relevant client. Saying so, I prefer not to dive into any framework at the moment ( quartz scheduler maybe?). Therefore, as I conclude, I'll need a