多线程28-总结
作者:互联网
线程总结
package com.faq.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) {
MyThread1 myThread1=new MyThread1();
myThread1.start();//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) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
//1.继承Tread类
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(){
System.out.println("mythread3");
return 100;
}
}
输出:
mythread1
mythread2
mythread3
100
线程同步
标签:总结,28,System,start,MyThread1,new,多线程,public,out 来源: https://blog.csdn.net/angel56789/article/details/114671669