JUC学习笔记(6)—创建线程的新方法Callable接口

public class CallableDemo
{
	public static void main(String[] args) throws InterruptedException, ExecutionException
	{
		FutureTask<Integer> ft = new FutureTask<Integer>(new MyThread());
		new Thread(ft, "AA").start();
		new Thread(ft, "BB").start();
		System.out.println(Thread.currentThread().getName()+"***********我是上课主线程");
		Integer result01 = ft.get();
		System.out.println("******result01: "+result01);

	} 
}

class MyThread implements Callable<Integer>
{
	@Override
	public Integer call() throws Exception
	{
		System.out.println("**********call() ****");
		//Thread.sleep(4000);
		return 1018;
	}
}

 

    原文作者:JUC
    原文地址: https://blog.csdn.net/java_kider/article/details/81321310
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞