多线程总结
Posted 123456dh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多线程总结相关的知识,希望对你有一定的参考价值。
package edu.wtbu;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
public class Demo04
public static void main(String[] args)
new MyThread1().start();
new Thread(new MyThread2()).start();
FutureTask<Integer> futureTask = new FutureTask<Integer>(new MyThread3());
new Thread(futureTask).start();
try
Integer integer=futureTask.get();
System.out.println(integer);
catch (InterruptedException e)
throw new RuntimeException(e);
catch (ExecutionException e)
throw new RuntimeException(e);
class MyThread1 extends Thread
@Override
public void run()
System.out.println("MyThread1");
class MyThread2 implements Runnable
@Override
public void run()
System.out.println("MyThread2");
class MyThread3 implements Callable
@Override
public Integer call() throws Exception
System.out.println("MyThread3");
return 10;
以上是关于多线程总结的主要内容,如果未能解决你的问题,请参考以下文章