threadpool

Active Thread Number in Thread Pool

断了今生、忘了曾经 提交于 2019-11-29 09:35:20
问题 When I write the below code, why do I get avaliable Thread number like 1022, 1020. I have to get 25 thread max as I am using thread pool. I guess the ouput thread number is the avaliable threads on the system. I need to get the avaliable thread number in my thread pool, in win form application. private void Foo() { int intAvailableThreads, intAvailableIoAsynThreds; // ask the number of avaialbe threads on the pool, //we really only care about the first parameter. ThreadPool

Calling Thread.Abort on a thread from a ThreadPool

独自空忆成欢 提交于 2019-11-29 09:11:47
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, DateTime> started = new Dictionary<Thread, DateTime>(); static void DoSomeWork(object foo) { lock

Using tasks/ ThreadPool on IIS application (asp .net)

余生长醉 提交于 2019-11-29 08:48:32
We have an asp.net application on an iis 7. we need to create an async process to do calculating (using a web service) and not keeping the client waiting, we used ThreadPool to do that (i prefer Tasks but i am a server side guy). My questions are : 1. if using a thread pool on iis does it take threads from the iis pool from clients or from the OS ? 2. What would you use Tasks or ThreadPool (Tasks give you much more i know but the UI guys like the pool). Tanks The ASP.NET host provides a single thread pool per process. So if you're using ThreadPool , then it's taking from the same pool that is

AsyncTasks do not get collected causing other AsyncTasks to not run

泄露秘密 提交于 2019-11-29 08:30:54
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. Could this be it, or will the AsyncTask be collected after it's finished no matter what? If that's

C# Execute Method (with Parameters) with ThreadPool

偶尔善良 提交于 2019-11-29 07:15:27
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(); }).Start(); } resetEvent.WaitOne(); However we would like to make use of ThreadPool rather than create our

Directed Graph Processing in Java

痞子三分冷 提交于 2019-11-29 06:49:48
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 ensure that a task isn't executed before its dependencies. brain Have a look at this previous question ,

Is there an out-of-the-box thread pool with multiple queues (that ensure serial processing of each queue)?

风格不统一 提交于 2019-11-29 05:37:57
Among all my tasks, I have some that must be processed serially (they can never run concurrently and they must be processed in order). I achieved that creating a separated thread pool with a single thread for each group of tasks that must be executed serially. It works but I don't have the resources for that. I don't control the number of groups, so I might end up with a ridiculous number of threads running simultaneously. Is there any way I can accomplish that with a single thread pool? Is there a thread pool with multiple blocking queues where I could ensure serial execution for each queue?

Stopping all thread in .NET ThreadPool?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 05:01:58
I am using ThreadPool in .NET to make some web request in the background, and I want to have a "Stop" button to cancel all the threads even if they are in the middle of making a request, so a simple bool wont do the job. How can I do that? The correct way to handle this is to have a flag object that you signal. The code running in those threads needs to check that flag periodically to see if it should exit. For instance, a ManualResetEvent object is suitable for this. You could then ask the threads to exit like this: evt.Set(); and inside the threads you would check for it like this: if (evt

Testing PriorityBlockingQueue in ThreadPoolExecutor

我是研究僧i 提交于 2019-11-29 04:54:24
I realized my ThreadPoolExecutor with PriorityBlockingQueue like in this example: https://stackoverflow.com/a/12722648/2206775 and wrote a test: PriorityExecutor executorService = (PriorityExecutor) PriorityExecutor.newFixedThreadPool(16); executorService.submit(new Runnable() { @Override public void run() { try { Thread.sleep(1000); Thread.sleep(1000); System.out.println("1"); } catch (InterruptedException e) { e.printStackTrace(); } } }, 1); executorService.submit(new Runnable() { @Override public void run() { try { Thread.sleep(1000); Thread.sleep(1000); System.out.println("3"); } catch

聊聊dubbo的ExecutionDispatcher

烈酒焚心 提交于 2019-11-29 04:02:47
序 本文主要研究一下dubbo的ExecutionDispatcher ExecutionDispatcher dubbo-2.7.3/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/dispatcher/execution/ExecutionDispatcher.java public class ExecutionDispatcher implements Dispatcher { public static final String NAME = "execution"; @Override public ChannelHandler dispatch(ChannelHandler handler, URL url) { return new ExecutionChannelHandler(handler, url); } } ExecutionDispatcher实现了Dispatcher接口,其dispatch方法返回的是ExecutionChannelHandler ExecutionChannelHandler dubbo-2.7.3/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache