1부터 100까지 도는 스레드풀을 종료시켜라
package april4;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class practice2 {
public static void main(String[] args) {
ExecutorService es = Executors.newFixedThreadPool(5);
es.execute(new thread1());
es.execute(new thread2());
try {
if(!es.awaitTermination(5, TimeUnit.SECONDS))
{es.shutdownNow();}
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); }
}
}
class thread1 extends Thread{
@Override
public void run(){
for(int i=0;i<100;i++){
System.out.println("쓰레드1 현재 " + i);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
System.out.println("셧다운 호출");
break;
}
}
}
}
class thread2 extends Thread{
@Override
public void run(){
for(int i=0;i<100;i++){
System.out.println("쓰레드2 현재 " + i);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
System.out.println("셧다운 호출");
break;
}
}
}
}
[람다함수] 1,10배열에서 큰수 중간 작은거 람다로출력 (0) | 2023.04.05 |
---|---|
[데몬스레드] 데몬스레드 종료하기 (0) | 2023.04.04 |
[람다함수] 곱하고 누나고 람다인터페이스로 (0) | 2023.04.04 |
[람다함수] 곱하고 더하고 빼는걸 람다함수로 (0) | 2023.04.04 |
[람다함수] 각종 문자 더하고 indexof 구하는 예제 (0) | 2023.04.04 |
댓글 영역