多线程总结
多线程总结
三种多线程类实现方法
package com.example.multi_thread;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
public class Overview {
public static void main(String[] args) {
new MyThread1().start();
new Thread(new MyThread2()).start();
FutureTask<Integer> mythred3 = new FutureTask<Integer>(new MyThread3());
new Thread(mythred3).start();
}
}
class MyThread1 extends Thread {
@Override
public void run() {
System.out.println("extends Thread");
}
}
class MyThread2 implements Runnable {
@Override
public void run() {
System.out.println("Runnable");
}
}
class MyThread3 implements Callable {
@Override
public Integer call() throws Exception {
System.out.println("Callable");
return 100;
}
}