Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Thread question  RSS feed

 
lalit kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple Thread question
I am new to java and very new to javathreads .
I want to build Multithreaded java application in which I will restrict the
No of concurrent threads depending upon the memory etc..
For example if I say that no of concurrent threads =10
And for(int I =0 ;I<=1000;I++)
I want to wait till first 10 thread died and again start 10 more thread
Plz help me out in this problem
I am very new to help accordingly
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
To wait for a Thread to die, you use the join() method:

The message isn't printed until the thread's run() method has terminated.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to attack this would be to create the specified number of threads in a pool and reuse them. This is not easy; I would not set out to write it myself! Doug Lea's Concurrency Package has a thread pool manager. Just using this stuff is not for the faint of heart. Let us know if you make it work!
 
Vinod Chandana
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Stan, I read his book abt 2 years back. I really dont remember well. But I did implement worker pool or replicated worker model. But I had implemented using interrupts.
Lalit, I would suggest u to reuse the threads instead of creating new threads. This can be pretty good interms of memory usage. But neway try smthg like this. Hope this helps.
Regards,
Vinod.

Originally posted by Stan James:
One way to attack this would be to create the specified number of threads in a pool and reuse them. This is not easy; I would not set out to write it myself! Doug Lea's Concurrency Package has a thread pool manager. Just using this stuff is not for the faint of heart. Let us know if you make it work!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!