package thread;

import java.util.concurrent.*;

/**
 * Created by 李恒名 on 2017/6/8.
 */
public class HowToCreateThread {

    public static void main(String[] args) {
        method1();
        method2();
        method3();
    }

    //继承java.lang.Thread
   public static void method1(){
       class Task extends Thread{

           @Override
           public void run() {
               System.out.println(Thread.currentThread().getName() +" Started");
           }
       }

       new Task().start();
   }
    //实现 java.lang.Runnable
   public static void method2(){
       class Task implements Runnable {

           @Override
           public void run() {
               System.out.println(Thread.currentThread().getName() +" Started");
           }
       }

       new Thread(new Task()).start();
   }
    //实现 java.util.concurrent.Callable
    public static void method3(){
        class Task implements Callable{

            @Override
            public Object call() throws Exception {
                System.out.println(Thread.currentThread().getName() +" Started");
                return "execute finished";
            }
        }

        ExecutorService es = Executors.newFixedThreadPool(1);
        Future future = es.submit(new Task());
        try {
            System.out.println(future.get());
        } catch (InterruptedException|ExecutionException e) { e.printStackTrace();}

        es.shutdown();

    }

}

@@ -229,32 +229,8 @@
 %7D%0A%0A 
-   //%E7%BB%A7%E6%89%BFjava.lang.Thread%0A
    p
@@ -256,18 +256,49 @@
 ethod1()
+ 
 %7B%0A
+        //%E7%BB%A7%E6%89%BFjava.lang.Thread%0A 
        c
@@ -321,19 +321,21 @@
 s Thread
+ 
 %7B%0A%0A
+ 
         
@@ -350,32 +350,33 @@
 ride%0A           
+ 
 public void run(
@@ -371,32 +371,33 @@
 ic void run() %7B%0A
+ 
                S
@@ -440,32 +440,33 @@
 ad().getName() +
+ 
 %22 Started%22);%0A   
@@ -465,34 +465,36 @@
 d%22);%0A           
+ 
 %7D%0A
+ 
        %7D%0A%0A      
@@ -490,24 +490,25 @@
   %7D%0A%0A       
+ 
 new Task().s
@@ -522,38 +522,13 @@
 %0A   
+ 
 %7D%0A
-    //%E5%AE%9E%E7%8E%B0 java.lang.Runnable
 %0A
+ 
    p
@@ -554,18 +554,52 @@
 ethod2()
+ 
 %7B%0A
+        //%E5%AE%9E%E7%8E%B0 java.lang.Runnable%0A 
        c
@@ -627,24 +627,25 @@
 Runnable %7B%0A%0A
+ 
            @
@@ -656,32 +656,33 @@
 ride%0A           
+ 
 public void run(
@@ -677,32 +677,33 @@
 ic void run() %7B%0A
+ 
                S
@@ -746,32 +746,33 @@
 ad().getName() +
+ 
 %22 Started%22);%0A   
@@ -775,26 +775,28 @@
 %0A           
+ 
 %7D%0A
+ 
        %7D%0A%0A  
@@ -789,24 +789,25 @@
 %0A        %7D%0A%0A
+ 
        new T
@@ -836,18 +836,59 @@
 t();%0A   
-%7D%0A
+ %7D%0A%0A    public static void method3() %7B%0A    
     //%E5%AE%9E%E7%8E%B0
@@ -922,42 +922,8 @@
 ble%0A
-    public static void method3()%7B%0A
     
@@ -956,16 +956,17 @@
 Callable
+ 
 %7B%0A%0A     
@@ -1103,16 +1103,17 @@
 Name() +
+ 
 %22 Starte
@@ -1137,33 +1137,41 @@
     
-return %22execute finished%22
+//%E6%B1%82%E5%92%8C%0A                return 1 + 1
 ;%0A  
@@ -1347,16 +1347,45 @@
 println(
+%22Calculate Completed Sum%EF%BC%9A%22 + 
 future.g
@@ -1432,9 +1432,11 @@
 tion
-%7C
+ %7C 
 Exec
@@ -1454,16 +1454,28 @@
 ion e) %7B
+%0A           
  e.print
@@ -1487,16 +1487,25 @@
 Trace();
+%0A        
 %7D%0A%0A     

update > callable create thread