How do I create a new thread and have it start running?
Created Apr 28, 2000
John Zukowski Creating a thread involves creating a new Thread and invoking its start() method. Calling start() causes the run() method of the Thread subclass or the Runnable object passed to the Thread constructor to execute.
Thread t1 = new Thread() {
public void run() {
for (int i=0; i<100; i++) {
System.out.println("Tastes Great");
}
}
};
Runnable r = new Runnable() {
public void run() {
for (int i=0; i<100; i++) {
System.out.println("Less Filling");
}
}
};
Thread t2 = new Thread(r);
t1.start();
t2.start();