threadpool

How to call a completion method everytime ThreadPool.QueueUserWorkItem method is returned

帅比萌擦擦* 提交于 2020-01-24 00:55:06
问题 I am using System.Threading.ThreadPool.QueueUserWorkItem(x => MyMethod(param1, param2, param3, param4, param5)); I want to call the following method from the main thread every time the call to MyMethod is completed: UpdateGui() { } How do I do that? Thanks! 回答1: Keep a global counter of work items queued and an object to protect it: int runningTasks = 0; object locker = new object(); Every time a task is added increment the counter: lock(locker) runningTasks++; System.Threading.ThreadPool

Analyzing output of !threadpool and !threads in windbg

丶灬走出姿态 提交于 2020-01-22 09:08:46
问题 I have generated dumps on four servers and am analyzing the output of !threadpool and !threads. I noticed the roughly consistent following output: 0:024> !threadpool CPU utilization 0% Worker Thread: Total: 2 Running: 0 Idle: 2 MaxLimit: 200 MinLimit: 2 Work Request in Queue: 0 Number of Timers: 27 Completion Port Thread:Total: 2 Free: 0 MaxFree: 4 CurrentLimit: 2 MaxLimit: 200 MinLimit: 2 !threads -special ThreadCount: 32 UnstartedThread: 0 BackgroundThread: 19 PendingThread: 0 DeadThread:

Time limit on individual threads with ExecutorService

眉间皱痕 提交于 2020-01-19 07:35:10
问题 I have an ExecutorService managing a number of Callables. The tasks that the Callables run are mostly black box transformations and number crunching. Under certain conditions, the data being transformed will oscillate and the thread will take over an hour to finish. For comparison, most threads are completed within a minute. It's been deteremined that the data from the long-running threads is not relevent. I would like to interrupt any thread that runs longer than a certain amount of time.

Play framework resource starvation after a few days

柔情痞子 提交于 2020-01-17 05:53:30
问题 I am experiencing an issue in Play 2.5.8 (Java) where database related service endpoints starts timing out after a few days even though the server CPU & memory usage seems fine. Endpoints that does not access the DB continue to work perfectly. The application runs on a t2.medium EC2 instance with a t2.medium MySQL RDS, both in the same availability zone. Most HTTP calls do lookups/updates to the database with around 8-12 requests per second, and there are also ±800 WebSocket connections

ScheduledExecutorService and ThreadPoolTaskExecutor that interrupts tasks after a timeout

元气小坏坏 提交于 2020-01-17 03:44:14
问题 I Used ExecutorService that interrupts tasks after a timeout.I use a ScheduledExecutorService for this. First I submitted the thread and it once to begin immediately and retain the future that is created. After that i use ScheduledExecutorService as a new task that would cancel the retained future after some period of time. //Start Spring executor to submit tasks ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) ApplicationContextProvider.getApplicationContext().getBean(

ThreadPoolExecutor - ArrayBlockingQueue … to wait before it removes an element form the Queue

假装没事ソ 提交于 2020-01-16 03:25:25
问题 I am trying to Tune a thread which does the following: A thread pool with just 1 thread [CorePoolSize =0, maxPoolSize = 1] The Queue used is a ArrayBlockingQueue Quesize = 20 BackGround: The thread tries to read a request and perform an operation on it. HOWEVER, eventually the requests have increased so much that the thread is always busy and consume 1 CPU which makes it a resource hog. What I want to do it , instead sample the requests at intervals and process them . Other requests can be

Spring ThreadPoolTaskExecutor never grows beyond corePoolSize

浪子不回头ぞ 提交于 2020-01-14 13:53:07
问题 I have configured Spring ThreadPoolTaskExecutor, having in mind 16 threads at least and up to 256 on the need-basis: <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="corePoolSize" value="16"/> <property name="maxPoolSize" value="256"/> <property name="queueCapacity" value="256"/> </bean> But as I can see from logs, thread pool size never exceeds corePoolSize : Thread pool size: 16/256, active count: 16 Why is that so? What have

How to print results of Python ThreadPoolExecutor.map immediately?

六月ゝ 毕业季﹏ 提交于 2020-01-13 19:28:26
问题 I am running a function for several sets of iterables, returning a list of all results as soon as all processes are finished. def fct(variable1, variable2): # do an operation that does not necessarily take the same amount of # time for different input variables and yields result1 and result2 return result1, result2 variables1 = [1,2,3,4] variables2 = [7,8,9,0] with ThreadPoolExecutor(max_workers = 8) as executor: future = executor.map(fct,variables1,variables2) print '[%s]' % ', '.join(map

How to print results of Python ThreadPoolExecutor.map immediately?

做~自己de王妃 提交于 2020-01-13 19:28:06
问题 I am running a function for several sets of iterables, returning a list of all results as soon as all processes are finished. def fct(variable1, variable2): # do an operation that does not necessarily take the same amount of # time for different input variables and yields result1 and result2 return result1, result2 variables1 = [1,2,3,4] variables2 = [7,8,9,0] with ThreadPoolExecutor(max_workers = 8) as executor: future = executor.map(fct,variables1,variables2) print '[%s]' % ', '.join(map

Thread control flow in async .NET Console program [duplicate]

有些话、适合烂在心里 提交于 2020-01-11 11:08:11
问题 This question already has an answer here : Async and await - difference between console, Windows Forms and ASP.NET (1 answer) Closed 9 months ago . I was messing around with async/await in C# just to dig into some of the thread control flow and stumbled upon an unusual behavior that I would really appreciate clarification on. It would make sense that the execution after await continues on a calling thread even if the Task itself was executed in background. And in fact that's exactly what