Home arrow static arrow Java Programming [Archive] - quick questions about java threads
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - quick questions about java threads
This topic has 3 replies on 1 page.

Posts:6
Registered: 6/22/04
quick questions about java threads  
Jun 24, 2004 9:00 AM



 
let's just say i open up 3threads at once, and my system has 5 processes to run these threads.

t1.start();
t2.start();
t3.start();

does java automatically close these threads after the program is finished running? or do i need a
t1.stop(); command and so forth to end each thread. the last thing i want to this program to suck all the resources out of this system.

and also. do i need to use a join(); method? these threads are all running in parallel concurrently. I can care less whether the first thread finishes before the 3rd, as long as they all do what i tell it to.

thanks.
 

Posts:6,750
Registered: 1/25/04
Re: quick questions about java threads  
Jun 24, 2004 9:05 AM (reply 1 of 3)



 
Sounds like you can just let them run to completion. I believe threads (BTW it's better to implement Runnable than extend Thread, though I don't know which you're doing) are automatically eligible for gc when they're done unless you maintain some other reference to them, and certainly when the JVM closes they'll be gone.
 

Posts:6
Registered: 6/22/04
Re: quick questions about java threads  
Jun 24, 2004 9:15 AM (reply 2 of 3)



 
here's what i'm doing. i'm having 3 different threads call the method callScript, which is a method in this same class that calls a unix script. all the 3 threads call the same script. is this ok? or will this face problems? i need suggestions because i can't really test this on the server yet. thanks.

public static void main ( String[] args ) throws Exception{

Thread t1 = new Thread(){
public void run(){
callScript(0);}
};

Thread t2 = new Thread(){
public void run(){
callScript(1);}
};

Thread t3 = new Thread(){
public void run(){
callScript(2);}
};

t1.start();
t2.start();
t3.start();
}
 

Posts:6,750
Registered: 1/25/04
Re: quick questions about java threads  
Jun 24, 2004 9:22 AM (reply 3 of 3)



 
As I said I would switch from Thread to Runnable. As for the script, I have no idea. Would calling that script 3 times in a row from outside Java cause problems? Whatever the answer, the same holds true for doing it from Java.
 
This topic has 3 replies on 1 page.