Questions tagged [threadpool]

A thread pool is a method to reuse existing threads, rather than always creating new ones. They allow for pooling resources in given limits and automatically assigning tasks to open workers. Use this tag when you have questions about implementing a thread pool, or using an existing thread pool implementation.

In multi-threaded applications, handling the various threads is a complicated task. Thread pool functionality is targeted to make it easier to use a large number of threads efficiently.

Because thread creation is relatively expensive, reusing threads in a pool can increase a programs performance. It can also help make better use of the available hardware threads by limiting the total number of threads that are created.

The main goal when using a thread pool is to be able to dynamically schedule work to a given set of workers. However, the original thread does not need to keep track of the thread creation itself, but forwards the thread management to the thread pool implementation. The thread pool will create new workers if necessary and destroy unused ones.

References

Related tags

4676 questions
2
votes
2 answers

A thread pool that lets me know when at least 1 has finished?

I need to use a thread pool in python, and I want to be able to know when at least 1 thead out or "maximum threads allowed" has finished, so I can start it again if I still need to do something. I has been using something like this: def…
jahmax
  • 8,181
  • 7
  • 26
  • 25
2
votes
0 answers

Android CPU Core Thread count

To get number of core we can use below line of code int CPU_COUNT = Runtime.getRuntime().availableProcessors() If device support hyper threading (HT) than int MAXIMUM_POOL_SIZE = CPU_COUNT * 2; Now, lets look AsyncTask stats for creating thread…
Amit Yadav
  • 32,664
  • 6
  • 42
  • 57
2
votes
1 answer

Can't INSERT into Sqlite3 database

I'm very desperate because I tried everything I could to make it work but no success... I've created a pool which is processing some text lines and then inserting them into the database. The problem is that it does not insert into the table…
Milano
  • 18,048
  • 37
  • 153
  • 353
2
votes
1 answer

Thread pool, Threadsafe Queue, OOP

Lets say there are some non-PC devices on an ethernet network and based on the given API, i can communicate with them using UDP. I would like to use a thread pool and a thread safe queue for the UDP communication. Every worker thread would have its…
john_who_is_doe
  • 389
  • 3
  • 18
2
votes
2 answers

Delphi: Wait for threads to finish

I read this article about creating a thread pool: http://delphi.about.com/od/kbthread/a/delphi-thread-pool-example-using-asynccalls.htm The reason I use the author's version is because of the waitAll function he made. This is working OK except for…
Amos
  • 1,321
  • 2
  • 23
  • 44
2
votes
4 answers

Am I deadlocking? Why?

I have a Silverlight 3 application which needs to call WCF service. The WCF service in turn calls an ASMX web service. When the WCF service call completes, the silverlight UI needs to be updated. WCF is being called in async. The thing is that the…
Saurabh Kumar
  • 2,329
  • 6
  • 32
  • 52
2
votes
1 answer

ThreadPoolTaskExecutor is not executing all the threads submitting to it

I have a ThreadPoolTaskExecutor for sending emails. Currently it's corePoolSize is 5, and queueCapacity is default i.e. max value of integer (unbounded queue)
munish
  • 453
  • 6
  • 22
2
votes
2 answers

How to parallelize database query using ThreadPool?

I'm bugfixing someone else's code where it takes ages to return the complete dataset in the following code: DataTable dt = someLib.GetDataTable("EXEC [dbo].[CMS_Content_GetAllContents]"); // Copy the DataTable data to list. foreach (DataRow dr in…
Chris
  • 657
  • 1
  • 9
  • 17
2
votes
1 answer

Thread parked on waiting on condition on AbstractFuture

so we are using Guava v18. We are going a lot of thread with this content: "catalina-exec-ajp2" daemon prio=10 tid=0x00007fb45c001800 nid=0x18aa waiting on condition [0x00007fb435151000] java.lang.Thread.State: WAITING (parking) at…
dierre
  • 7,140
  • 12
  • 75
  • 120
2
votes
1 answer

How to limit the number of concurrent workers?

I have a function which I would like to be executed several times in parallel, but with only a defined number of instances at the same time. The natural way to do this seems to be to use multiprocessing.Pool. Specifically, the documentation says…
WoJ
  • 27,165
  • 48
  • 180
  • 345
2
votes
1 answer

backgroundrb thread_pool.defer method logger output goes to where?

It seems like due to the threading issue logger.warn (thats what I tested) doesn't generate any output? my code is similar to this: def deliver(args) logger.info "delivery start" thread_pool.defer(:deliver_deferred, args) logger.info "delivery…
William Yeung
  • 10,368
  • 9
  • 36
  • 42
2
votes
2 answers

Basic threadpool question

Let me preface this with the disclaimer that I am very new to multithreading and may be missing something obvious. I'm currently using the below code to process all the files in a directory. My question is if it would ever be possible for a thread…
Ryan
  • 23
  • 2
2
votes
1 answer

calling an api concurrently in python

I need to talk to an api to get information about teams. Each team has a unique id. I call the api with that id, and I get a list of players on each team (list of dicts). One of the keys for a player is another id that I can use to get more…
Mark
  • 2,058
  • 2
  • 35
  • 64
2
votes
3 answers

C++ ThreadPool is not running parallel

I've tried to implement a ThreadPool, but unfortunately I'm running into some problems. This is what I have already. //includes ... void call() { std::cout << "Hi i'm thread no " << std::this_thread::get_id() << std::endl; …
user1235183
  • 3,002
  • 1
  • 27
  • 66
2
votes
1 answer

How to use Thread Pool and Mutex in c#?

I try to learn how to use Thread Pool and Mutex, as a practice I'm trying to make an application that copy files from one path in the computer to another path in the computer. To do this application I used Thread Pool (so a few copies could happen…
ShaqD
  • 63
  • 1
  • 10