标签:lock public rri rate main exception integer cep int
线程创建三个方法:
1.继承thread类
2.实现runnable接口
3.实现callable接口
实例:
//线程的创建方法
public class TestNew {
public static void main(String[] args) {
new Mythread1().start();
Mythread2 mythread2=new Mythread2();
new Thread(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 | ExecutionException e) {
// TODO Auto-generated catch block
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;
}
}
标签:lock public rri rate main exception integer cep int
原文地址:https://www.cnblogs.com/yuanlianyao/p/14532280.html