threadpool

Calling Thread.Abort on a thread from a ThreadPool

好久不见. 提交于 2019-11-28 02:35:33
问题 My co-worker is using a third-party .NET library for which we don't have the source code. We're using a ThreadPool to have a lot of threads call into this library, and occasionally one of the threads will just hang forever while the rest of them merrily chug along. So we want to use the dreaded Thread.Abort to kill such threads. I've done this before when spinning up my own threads, but I've never used a ThreadPool. If we track the start times of each task like this: static Dictionary<Thread,

AsyncTasks do not get collected causing other AsyncTasks to not run

吃可爱长大的小学妹 提交于 2019-11-28 02:06:13
问题 My app uses a lot of AsyncTasks. It is a web app after all. And when I keep track of the Debug tab, I notice every AsyncTask says running behind it and after 5 AsyncTasks, I can't start any AsyncTasks. I fixed it by changing the executor to THREAD_POOL_EXECUTOR which allows 15 threads to be pooled. But the AsyncTasks still show as running. The AsyncTasks all have InputStreams in them and BufferedReaders in them to read the JSON, but I never call the close() method on the Streamers and Readers

Why Thread.Sleep affects creation of new Tasks?

此生再无相见时 提交于 2019-11-28 02:04:38
private static void Main(string[] args) { for (int i = 0; i < 1000; i++) { Task.Factory.StartNew(() => { Thread.Sleep(1000); Console.WriteLine("hej"); Thread.Sleep(10000); }); } Console.ReadLine(); } Why this code won't print 1000 times "hej" after one second? Why Thread.Sleep(10000) has an impact on code behavior? Factory.StartNew effectively delegates the work to ThreadPool . Threadpool will create number of threads immediately to respond the request as long as threads count is less than or equal to processor count. Once it reaches processor count, threadpool will stop creating new threads

C# Execute Method (with Parameters) with ThreadPool

妖精的绣舞 提交于 2019-11-28 00:52:39
问题 We have the following piece of code (idea for this code was found on this website) which will spawn new threads for the method "Do_SomeWork()". This enables us to run the method multiple times asynchronously. The code is: var numThreads = 20; var toProcess = numThreads; var resetEvent = new ManualResetEvent(false); for (var i = 0; i < numThreads; i++) { new Thread(delegate() { Do_SomeWork(Parameter1, Parameter2, Parameter3); if (Interlocked.Decrement(ref toProcess) == 0) resetEvent.Set(); })

Why *not* change the priority of a ThreadPool (or Task) thread?

泄露秘密 提交于 2019-11-27 23:28:22
There are many places across the web and Stack Overflow where one is discouraged from changing the priority of a ThreadPool thread or TPL Task . In particular: "You have no control over the state and priority of a thread pool thread." "The runtime manages the thread pool. You have no control over the scheduling of the thread, nor can you change the thread's priority." "You should not change the Culture or Priority or... of a PoolThread. Just like you don't paint or re-decorate a rental car." "There are several scenarios in which it is appropriate to create and manage your own threads instead

Threads within threads in Java?

荒凉一梦 提交于 2019-11-27 23:07:04
I am currently thinking about how to design a multithreading system in Java that needs to do some heavy network processing and database storage. The program will launch three basic threads at first. Along these basic threads, I would like to launch other threads not from the main program but from two of the threads. Is it possible for a thread to launch another thread leading to some sort of a hierarchy like: > Parent ->t0 thread1 -> t1 tread1.1 > ->t0 thread2 > ->t0 thread3 -> t2 thread3.1 t0= inital time t1,t2 = time at a point in the running thread t1 != t2 If not could somebody provide a

With ThreadPoolExecutor, how to get the name of the thread running in the thread pool?

妖精的绣舞 提交于 2019-11-27 22:16:20
问题 I'm using a ThreadPoolExecutor in Java to manage a lot of running threads. I've created my own simple ThreadFactory so I can give the threads better names. The issue is that the name gets set in the Thread when the thread pool is first created and is not tied to the task that the thread pool is actually running. I understand this... my Runnables and Callables--though they have names--are actually one level of abstraction down from the ThreadPoolExecutor 's running threads. There have been

InheritableThreadLocal and thread pools

梦想与她 提交于 2019-11-27 22:15:10
问题 I have a problem which I don't really think has a solution but I'll try here anyway. My application uses a thread pool and some of the threads in this pool have an inheritable thread local variable. I've extended the ThreadPoolExecutor class to essentially clear out the thread local variable (in the afterExecute call back method) when a thread is done executing. I understand that when you have an InheritableThreadLocal variable, the childValue() method is called when the thread is initialized

boost::asio threadpool vs. io_service_per_cpu design

你说的曾经没有我的故事 提交于 2019-11-27 20:18:49
Currently I´m not sure, I try to make a high-performance server, I got a 6Core CPU, so if I would use the "io_service_per_cpu" design, I have 6 io_service´s. I already heard that the threadpool design isn´t the best one, but I´m not sure about that. What knowledge do you have? Someone already made a Stress test with each, or something else? Sam Miller In my experience it is vastly easier to approach asynchronous application design with the following order: single thread and a single io_service multiple threads, each invoking io_service::run() from a single io_service . Use strands for handlers

What is the difference between SynchronizationContext.Send and SynchronizationContext.Post?

微笑、不失礼 提交于 2019-11-27 20:18:40
问题 Thanks to Jeremy Miller's good work in Functional Programming For Everyday .NET Development, I have a working command executor that does everything I want it to (do heavy lifting on the thread pool, send results or errors back to the synchronization context, and even post progress back to the synchronization context), but I can't explain why it uses SynchronizationContext.Send from the thread-pool and Synchronization.Post from the Func passed into the method that does the heavy lifting. I