running some 50 threads at a given time

Hi,

I am having one requirement.I created some 1000 threads to access a resource .am running 50 threads at a time(i.e only 50 threads has to at a given period of time) but when any one of the thread is completed another thread has to start i.e 51 st thread has to start.so at any given time there will be only 50 threads running on the whole.similarly further threads also to be start execution. please help me to this situation if possible just give me a sample codes for this situation.

I need it in urgent.

karthikeyan

karthisys@yahoo.co.in

[574 byte] By [karthisysa] at [2007-10-3 10:23:25]
# 1
(i dunno if this is right im just guessing so let me know if this will work or not)i = 50(or amount of threads that u want)thread(){***on finish call myclass()****i--;}myclass(){while( i<50){start a
SvHa at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...
# 2
This is a job for http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Semaphore.html
ejpa at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...
# 3

You don't say why you want to do this, but it sounds to me like what you really want is a thread pool, i.e. 50 threads which wait for work to come their way via a task queue. Rather than creating new threads the existing ones finish one task and take on the next waiting to be done. There are extensive facilities for this in the new java.util.concurency package.

malcolmmca at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks for your suggestion. am trying the same way. please if you find some better way suggest me.
karthisysa at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...
# 5
By this way i can start 50 out of 1000threads but my requirement is if 1out of 50 started threads finished execution then immediately i need to start next thread out of 1000 threads. so on the whole at any cost there should be 50 threads executing.
karthisysa at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...
# 6
This package is available in java 5.0 but am restricted to use j2se 1.4so i can't use this package
karthisysa at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...
# 7
http://forum.java.sun.com/thread.jspa?threadID=589041&messageID=3052547
JoachimRohdea at 2007-7-15 5:45:09 > top of Java-index,Java Essentials,Java Programming...