I'm writing a small program to see how multiple threads can be run in Java. Not sure why I'm not getting any output:
class NuThread implements Runnable {
NuThread() {
Thread t = new Thread(this, "NuThread");
t.start();
}
public void run() {
try {
for (int i=0; i<5; i++) {
Thread th = Thread.currentThread();
System.out.println(th.getName() + ": " + i);
Thread.sleep(300);
}
} catch (InterruptedException e) {
Thread th = Thread.currentThread();
System.out.println(th.getName() + " interrupted.");
}
}
}
public class MultiThreadDemo {
public static void main(String[] args) {
NuThread t1, t2, t3;
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
System.out.println("Main interrupted.");
}
}
}