标签:tar turn extend pac 接口 void static integer ble
package cn.ruhsang.gaoji;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
//回顾线程池的创建
public class ThreadNew {
public static void main(String[] args) {
//1.第一个方法的调用
new MyThread1().start();
//2.第二个方法的调用
MyThread2 myThread2 = new MyThread2();
new Thread(myThread2).start();
//3.第三个方法的启动
FutureTask<Integer> futureTask = new FutureTask<Integer>(new MyThread3());
new Thread(futureTask).start();
try {
Integer integer = futureTask.get();
System.out.println(integer);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
//1.继承Thread类
class MyThread1 extends Thread{
@Override
public void run() {
System.out.println("MyThread1");
}
}
//2.实现Runnable接口
class MyThread2 implements Runnable{
@Override
public void run() {
System.out.println("MyThread2");
}
}
//3.实现callable接口
class MyThread3 implements Callable<Integer>{
@Override
public Integer call() throws Exception {
System.out.println("MyThread3");
return 100;
}
}
标签:tar turn extend pac 接口 void static integer ble
原文地址:https://www.cnblogs.com/nigustudent/p/14878610.html