线程创建的方式

package com.fh.interview;

import java.util.concurrent.*;

/**线程创建的方式
 * @author
 * @create 2018-05-27 下午2:58
 **/
public class CreateTHread {

    public static void main(String[] args) {
        Thread threadA = new Thread("threadA"){
            @Override
            public void run() {
                System.out.println("启动了A");
            }
        };
        threadA.start();
        Thread threadB = new Thread(new Runnable() {
            public void run() {
                System.out.println("启动了B");
            }
        },"threadB");
        threadB.start();
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Future<String> future=executorService.submit(new Callable<String>() {
            public String call() throws Exception {
                return "启动了C";
            }
        });

        try {
            System.out.println(future.get());
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
View Code

线程状态转换

 

posted @ 2018-05-27 15:10  默默行走  阅读(97)  评论(0编辑  收藏  举报