I'm trying to create my first server, a simple chat server.
I have a Runnable
class called cCleanThread
that creates a thread that uses sleep to call
cGlobals.mUserList.Clean();
every 10 seconds.
I would like to have it so each instance of cCleanThread
would have its own mUserList
object. I can't figure out a easy way to do this.
I figured I would somw how have to pass in a parameter for a mUserList
when I create my cCleanThread
object?
code
public class cCleanThread implements Runnable {
Thread runner;
public cCleanThread() {
}
public cCleanThread(String threadName) {
runner = new Thread(this, threadName); // (1) Create a new thread.
System.out.println(runner.getName());
runner.start(); // (2) Start the thread.
}
public void run() {
//Display info about this particular thread
System.out.println(Thread.currentThread());
while(true)
{
try {
Thread.sleep(20*1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cGlobals.mUserList.Clean();
}
}
}