Thread questions.

Ok, I have decided to write a new mini thread program so I can learn it...

class printerimplements Runnable{

publicvoid run(){

while (1==1){//WHILE HERE?

System.out.println("TEST");

}

}

}

class threadTest{

publicstaticvoid main(String[] args){

threadTest frame =new threadTest();

while (1==1){//WHILE HERE?

printer ww =new printer();

Thread wt =new Thread(ww);

wt.start();

}

}

}

Notice where I have "WHILE HERE?" If I am threading an application, which is the better one if I want to have it print "TEST" over and over while threading?, Im guessing its in the threaded... but then it leaves me with the problem of sleep... I know I need it within a Try block, and I have tried doing so but I cannot get it to work. I probably have the Try block in the wrong place.

EDIT: Ok, I got the sleep to work... and I assume I am correct about while being in the threaded class?

Message was edited by:

Evilsanta

[1883 byte] By [Evilsantaa] at [2007-11-26 18:49:48]
# 1
Put the while loop in the run() method.
CaptainMorgan08a at 2007-7-9 6:23:50 > top of Java-index,Java Essentials,New To Java...
# 2
Thank you!
Evilsantaa at 2007-7-9 6:23:50 > top of Java-index,Java Essentials,New To Java...
# 3

Also, is there a way to cycle through all my threads?

Right now I am working on a small chat application, and it uses threads, but if I send the server a message, it only returns the message to the client that sent it. How do I have it go through all the clients and send a message to them?

In other languages I would do something like this...

for (each client connected){

send packet

}

Or something similar, how would I do this with threads?

Evilsantaa at 2007-7-9 6:23:50 > top of Java-index,Java Essentials,New To Java...