threadpool

Running a task in parallel to another task

房东的猫 提交于 2019-11-27 03:39:30
问题 I have the following Foo class that uses FooProcessor class. So what i want to do is, while running cp1 instance process method, in parallel I want to run cp2.process() . public class Foo { public static void main(String [] args){ FooProcessor cp1 = new FooProcessor(); FooProcessor cp2 = new FooProcessor(); cp1.process(); // in parallel process cp2.process(); } } public class FooProcessor { public void process(){ System.out.println("Processing.."); } } However, i want cp1 sequentially, so i

Deadlock in ThreadPool

拜拜、爱过 提交于 2019-11-27 02:43:31
问题 I couldn't find a decent ThreadPool implementation for Ruby, so I wrote mine (based partly on code from here: http://web.archive.org/web/20081204101031/http://snippets.dzone.com:80/posts/show/3276 , but changed to wait/signal and other implementation for ThreadPool shutdown. However after some time of running (having 100 threads and handling about 1300 tasks), it dies with deadlock on line 25 - it waits for a new job there. Any ideas, why it might happen? require 'thread' begin require

Always Running Threads on Windows Service

China☆狼群 提交于 2019-11-27 02:26:02
问题 I'm writing a Windows Service that will kick off multiple worker threads that will listen to Amazon SQS queues and process messages. There will be about 20 threads listening to 10 queues. The threads will have to be always running and that's why I'm leaning towards to actually using actual threads for the worker loops rather than threadpool threads. Here is a top level implementation. Windows service will kick off multiple worker threads and each will listen to it's queue and process messages

Java ExecutorService pause/resume a specific thread

爱⌒轻易说出口 提交于 2019-11-27 02:18:32
问题 Is there a way to use ExecutorService to pause/resume a specific thread? private static ExecutorService threadpool = Executors.newFixedThreadPool(5); Imagine that I want to stop the thread wich as the id=0 (assuming that to each one is assigned an incremental id until the size of the threadpool is reached). After a while, by pressing a button let's say, I want to resume that specific thread and leave all the other threads with their current status, which can be paused or resumed. I have found

Specify task order execution in Java

試著忘記壹切 提交于 2019-11-27 02:12:19
问题 I've searched a lot but couldn't find any solution. I use java thread pool in such way: ExecutorService c = Executors.newFixedThreadPool(3); for (int i = 0; i < 10; ++i) { c.execute(new MyTask(i)); } In such way Tasks are executed in consequent order (as in queue). But I need change "select next task" strategy. So I want assign to each task specify priority (it isn't thread priority) and execute tasks correspond to these priorities. So when executor have finished another task it chooses next

Wait until all threads finished their work in ThreadPool

不问归期 提交于 2019-11-27 02:11:22
问题 i have this code: var list = new List<int>(); for(int i=0;i<10;i++) list.Add(i); for(int i=0;i<10;i++) { ThreadPool.QueueUserWorkItem( new WaitCallback(x => { Console.WriteLine(x); }), list[i]); } And i want to know when all threadpools threads finished their work. How i can to do that? 回答1: You'll need to track this yourself. One option for this is to use a counter and a reset event: int toProcess = 10; using(ManualResetEvent resetEvent = new ManualResetEvent(false)) { var list = new List

Is accept() thread-safe?

百般思念 提交于 2019-11-27 02:05:34
I'm currently writing a simple webserver in C for a course I'm doing. One requirement is for us to implement a thread pool to handle connections using pthreads. I know how I would go about doing this roughly(calling accept in a main thread and passing the file descriptor to a freee thread), however my friend suggested an alternate method than the one I had in mind: creating all my threads up front, and getting them all to loop forever on a call to accept. The idea being that accept will block all the idle threads and when a connection comes in, only giving the file descriptor to one. Then when

Threadpool in IIS context

偶尔善良 提交于 2019-11-27 01:59:09
问题 I have a general question about System.Threading.Threadpool when run in a webapplication on IIS. Say we have 2 requests execute at once, and we fire up a couple of threads through the ThreadPool.QueueUserWorkItem method. Will the two requests share the ThreadPool, or will the calls to the ThreadPool from the two requests operate in a two separate pools? This is in IIS6 and 7. Thanks for any insight. 回答1: Here is a quote from the MSDN documentation about the ThreadPool class: There is one

How can I kill a pthread that is in an infinite loop, from outside that loop?

眉间皱痕 提交于 2019-11-27 00:55:25
问题 I create a thread and I put it into an infinite loop. I get memory leaks when checking the code with valgrind . Here is my code: #include <pthread.h> #include <time.h> void thread_do(void){ while(1){} } int main(){ pthread_t th; pthread_create(&th, NULL, (void *)thread_do, NULL); sleep(2); /* I want to kill thread here */ sleep(2); return 0; } So a thread is created in main and just runs thread_do() all the time. Is there a way to kill it from inside main after 2 seconds? I have tried both

How to utilize a thread pool with pthreads?

不羁的心 提交于 2019-11-27 00:46:00
问题 I have a queue of jobs and I want to make a pool of four threads where I can throw my jobs at. What I am stuck at is in how to make the threads and keep them suspended while there is no work. JOB QUEUE | job1 | job2 | job3 | job4 | .. THREAD POOL | thread1 | thread2 | thread3 | thread4 | To create the threads I have currently at the initialisation point: for (t=0; t<num_of_threads; t++){ pthread_create(&(threads[t]), NULL, doSth2, NULL); } Where num_of_threads=4 and doSth2 is a function with