package javaapplication1;
public class JavaApplication1 implements Runnable{
public void run() {
for (int i = 0; i < 4; i++) {
System.out.println("Child thread : " + i);
try {
Thread.sleep(30);
} catch (InterruptedException ie) {
System.out.println("Child thread error: " + ie);
}
}
System.out.println("Child thread end ok");
}
public static void main(String[] args) {
Thread t = new Thread(new JavaApplication1(), "My Thread");
t.start();
for (int i = 0; i < 6; i++) {
System.out.println("Main thread : " + i);
try {
Thread.sleep(70);
} catch (InterruptedException ie) {
System.out.println("Main thread error: " + ie);
}
}
System.out.println("Main thread end ok");
}
}
/*
run:
Main thread : 0
Child thread : 0
Child thread : 1
Child thread : 2
Main thread : 1
Child thread : 3
Child thread end ok
Main thread : 2
Main thread : 3
Main thread : 4
Main thread : 5
Main thread end ok
*/