dcsimg
passing paramets to multiple threads in a loop.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   abhay_sahai
Posted On:   Friday, July 19, 2002 03:52 AM

Hello i need to pass parameter to threads that are created in a loop like: method start while(condition){ new myThread("parameter", myThreadGroup); } Here all the threads are created myThreadGroup.join(); method ends I designed a class myThreadGroup using ExtendedThreadGroup Is there any method by which I can join() to a group of threads instead of a single one and used the method join, still no go. The method returned before threads were over. Suggest    More>>

Hello i need to pass parameter to threads that are created in a loop like:

method start

while(condition){

new myThread("parameter", myThreadGroup);

} Here all the threads are created


myThreadGroup.join();

method ends


I designed a class myThreadGroup using ExtendedThreadGroup Is there any method by which I can join() to a group of threads instead of a single one and used the method join, still no go. The method returned before threads were over.


Suggest

   <<Less

Re: passing paramets to multiple threads in a loop.

Posted By:   abhay_sahai  
Posted On:   Friday, July 19, 2002 05:40 AM

sorry to have bothered you guys I myself found the answer all I have to do is to call super() in the constructor of myThread. like
public class ThreadsParam implements Runnable {

public static void main(String s[]){

ThreadGroup th= new ThreadGroup("T");



for(int i =0; i < 10; i++)

new myThread(th,"m");



System.out.println("HI");

System.out.println(th.activeCount());

}

public void run(){

for (int i=0; i<1000; i++);

}

}



class myThread extends Thread{

private String str;

ThreadGroup tgrp;

public myThread( ThreadGroup t, String st){

super(t,st);

str=st;

tgrp=t;



}

public void run()

{

for (int i=0; i<1000; i++);

}

}


Hope someone like me gets benefitted from this.
About | Sitemap | Contact