• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to spawn out multiple thread

 
Amitabh Sinha55555
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir/Madam
I would like to spawn out multiple thread form a main thread and each thread should communicate with the main thread to inform the time when that particular thread started and completed the process to the main thread .The number of threads to be spawned out varies from 1 to 10000
I am not able to get a good content on Thread Pooling .I hope thesolution lies in this.
Can any one help me with the codes or concept of the implementation of Thread Pooling

Rgds
Amitabh Sinha
 
Andy Ceponis
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure if this is what your looking for, but you can esily create multiple threads with a simple for loop. But i highly doubt you willbe able to create more than a few hundred threads unless you have a powerful machine. I read somewhere that the most threads possible is like 2000 or so.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you are looking for is Thread pooling, what you need to do is design the worker object for achieving the task, then turn it into a threaded object.
The pooling part means that rather than creating a new thread each time a 'worker object' is required, you create a bunch of them at the start and hand them out as required. If a worker is required but there are none available inthe pool, it depends on the design of the pool. Sometimes you can allow the pool to grow and contract but more likely you will tell whoever made the request to wait.
To give an example, if you design a multi-threaded web server:
* 'main' thread monitors socket for requests
* when request comes in, thread is retrieved from the pool and the request details are passed to that worker
* if no threads are available in the pool the request is buffered until a thread is available
* when a worker is finished it goes back into the pool.
Hope this was step forward
Dave.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!