threadpool

Number of active tasks using ThreadPoolExecutor

南楼画角 提交于 2019-11-30 20:46:24
I am using a ThreadPoolExecutor to execute tasks in my Java application. I have a requirement where I want to get the number of active tasks in the queue at any point in time in the executor queue . I looked up at the javadoc for ThreadPoolExecutor and found two relevant methods: getTaskCount() and getCompletedTaskCount() . Per the documentation, I could get the number of scheduled tasks and completed tasks from the above two methods respectively. But I am not able to find a solution for getting the number of active tasks in the queue at any point in time. I can do something like: getTaskCount

How to create threads in ASP.NET pages from CLR thread pool instead of ASP.NET pool?

夙愿已清 提交于 2019-11-30 18:29:21
问题 If I create a new thread on an ASP.NET page the IsThreadPoolThread property is true. First question is, is it from ASP.NET pool or CLR pool ? Second question is, if it is from ASP.NET pool then how to create a thread from CLR and don't use ASP.NET pool ? I need a synchronous solution for long-running requests (full story). 回答1: First off, there is no difference between the ASP.NET thread pool and the CLR thread pool. ASP.NET processes pages on the CLR thread pool, so your ASP.NET pages will

Detecting that a ThreadPool WorkItem has completed/waiting for completion

为君一笑 提交于 2019-11-30 17:46:30
问题 For whatever reason, ThreadPool 's QueueWorkItem doesn't return an IAsyncResult or some other handle to the work item, which would allow to wait until it's completed. There are RegisterWait... methods, but you have to pass a WaitHandle and creating them is expensive (see IAsyncResult documentation, which advises you to delay creating a WaitHandle until requested). The Task Parallel Library will fix this lack, but there is a long wait before that's available. So, are there any problems with

Ninject - In what scope DbContext should get binded when RequestScope is meaningless?

徘徊边缘 提交于 2019-11-30 17:37:40
In an MVC / WebAPI environment I would use InRequestScope to bind the DbContext . However, I am now on a Console application / Windows service / Azure worker role (doesn't really matter, just there's no Web request scope), which periodically creates a number of Tasks that run asynchronously. I would like each task to have its own DbContext , and since tasks run on their own thread, I tried binding DbContext using InThreadScope . Unfortunately, I realize that the DbContext is not disposed when a task is finished. What actually happens is, the thread returns to the Thread Pool and when it is

Twisted: Creating a ThreadPool and then daemonizing leads to uninformative hangs

允我心安 提交于 2019-11-30 17:13:18
问题 I am developing a networked application in Twisted, part of which consists of a web interface written in Django. I wish to use Twisted's WSGI server to host the web interface, and I've written a working "tap" plugin to allow me to use twistd . When running the server with the -n flag (don't daemonize) everything works fine, but when this flag is removed the server doesn't respond to requests at all, and there are no messages logged (though the server is still running). There is a bug on

How can I accomplish ThreadPool.Join?

浪子不回头ぞ 提交于 2019-11-30 15:54:40
问题 I am writing a windows service that uses ThreadPool.QueueUserWorkItem() . Each thread is a short-lived task. When the service is stopped, I need to make sure that all the threads that are currently executing complete. Is there some way of waiting until the queue clears itself? 回答1: You could create an event (e.g. ManualResetEvent ) in each thread, and keep it in a synchronised list (using the lock construct). Set the event or remove it from the list when the task is finished. When you want to

HttpWebRequest and I/O completion ports

那年仲夏 提交于 2019-11-30 15:48:45
问题 I'm working on an application that requires for one type of message to go hit a database, and the other type of message to go and hit some external xml api. I have to process A LOT... one of the big challenges is to get HttpWebRequest class performing well. I initially started with just using the standard synchronous methods and threadpooling the whole thing. This was not good. So after a bit of reading I saw that the recommended way to do this was to use the Begin/End methods to delegate the

How can I accomplish ThreadPool.Join?

梦想的初衷 提交于 2019-11-30 14:40:34
I am writing a windows service that uses ThreadPool.QueueUserWorkItem() . Each thread is a short-lived task. When the service is stopped, I need to make sure that all the threads that are currently executing complete. Is there some way of waiting until the queue clears itself? You could create an event (e.g. ManualResetEvent ) in each thread, and keep it in a synchronised list (using the lock construct). Set the event or remove it from the list when the task is finished. When you want to join, you can use WaitHandle.WaitAll ( MSDN documentation ) to wait for all the events to be signalled. It

How to log correct context with Threadpool threads using log4net?

久未见 提交于 2019-11-30 13:04:30
问题 I am trying to find a way to log useful context from a bunch of threads. The problem is that a lot of code is dealt with on Events that are arriving via threadpool threads (as far as I can tell) so their names are not in relation to any context. The problem can be demonstrated with the following code: class Program { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); static void Main(string[] args) { new

(How) Does TPL use (CLR) Thread Pool?

£可爱£侵袭症+ 提交于 2019-11-30 12:37:40
I am currently researching Task Parallel Library and I read somewhere that TPL actually uses thread pool mechanism from CLR-Level. I couldn't find any article confirming this information. I know, TPL has task queues for each thread and uses some special work-stealing algorithm for balancing. As far as I know, it creates one thread for each processor. Thread pools started to use task objects of TPL since .NET 4. I can not understand how TPL uses the thread pool. Thread-Pool pattern states, the work items are queued and the free threads in thread pool takes one from this queue. TPL however store