Executors.新SingleThreadExecutor()テスト
2909 ワード
public class Qiao3 {
public static void main(String[] args) {
Thread thread1 = new Thread(()->{
System.out.println("111");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("222");
});
Thread thread2 = new Thread(()->{
System.out.println("333");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("444");
});
Thread thread3 = new Thread(()->{
System.out.println("555");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("666");
});
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(thread1);
executorService.submit(thread2);
executorService.execute(thread3);
System.out.println("ok");
}
}