Friday, October 5, 2012

Create Java inline thread

import java.util.Date;

public class InlineThreadDemo {
 public static void main(String[] args) {
System.out.println( "parent thread " + new Date(System.currentTimeMillis())); // launch child thread using
// inline declaration
new Thread( new Runnable() {
public void run() {
try {
Thread.sleep(10 * 1000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println( "child thread " + new Date(System.currentTimeMillis()));
}
}).start();

System.out.println( "parent thread " + new Date(System.currentTimeMillis())); }}


No comments: