public class MyThread extends Thread {
public void run ( ) {
System . out. println ( "hello world" ) ;
}
}
public static void main ( String [ ] args) {
MyThread t = new MyThread ( ) ;
t. start ( ) ;
}
public class MyThread implements Runnable {
public void run ( ) {
System . out. println ( "hello world" ) ;
}
}
public static void main ( String [ ] args) {
MyThread t = new MyThread ( ) ;
new Thread ( t) . start ( ) ;
}
public class MyThread implements Callable < String > {
public String call ( ) {
return "hello world" ;
}
}
public static void main ( String [ ] args) throws Exception {
MyThread t = new MyThread ( ) ;
FutureTask < String > task = new FutureTask < > ( t) ;
new Thread ( task) . start ( ) ;
System . out. println ( task. get ( ) ) ;
System . out. println ( task. isDone ( ) ) ;
System . out. println ( task. isCancelled ( ) ) ;
System . out. println ( task. cancel ( true ) ) ;
}
public static void main ( String [ ] args) {
ExecutorService executor = Executors . newCachedThreadPool ( ) ;
executor. execute ( new Runnable ( ) {
public void run ( ) {
System . out. println ( "hello world" ) ;
}
} )
executor. shutdown ( ) ;
}
public static void main ( String [ ] args) {
new Thread ( ) {
public void run ( ) {
System . out. println ( "hello world" ) ;
}
}
. start ( ) ;
}