线程创建的方式

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

线程状态转换

猜你喜欢

转载自www.cnblogs.com/nihaofenghao/p/9096154.html