public class Thread1
{
public static void main(String[] arg)
{
Runnable r1 = new Runnable()
{
public void run() {
try {
while (true) {
System.out.println("
Thread 1 run after 4 seconds
");
Thread.sleep(4000);
}
} catch (InterruptedException iex)
{}
}
};
Runnable r2 = new Runnable()
{
public void run() {
try {
while (true) {
System.out.println("
Thread 2 run after 8 seconds
");
Thread.sleep(8000);
}
} catch (InterruptedException iex)
{}
}
};
Thread thr1 = new Thread(r1);
Thread thr2 = new Thread(r2);
thr1.start();
thr2.start();
}
}
Thread 1 run after 4 seconds
Thread 1 run after 4 seconds
Thread 2 run after 8 seconds
Thread 1 run after 4 seconds
Thread 1 run after 4 seconds
Thread 2 run after 8 seconds
No comments:
Post a Comment