우선 스레드 풀은 미리 생성된 스레드의 집합 !!
ExecutorService 사용하기: Java에서는 ExecutorService 인터페이스를 사용하여 스레드풀을 생성하고 관리할 수 있다. ExecutorService를 사용하면 스레드풀의 크기, 작업 큐의 크기 등을 설정할 수 있다.
ExecutorService executorService = Executors.newFixedThreadPool(10);
ThreadPoolExecutor 클래스 사용하기: ThreadPoolExecutor 클래스를 직접 사용하여 스레드풀을 생성할 수도 있다.
이는 ExecutorService 인터페이스의 구현체인데, 세밀한 설정이 가능
ThreadPoolExecutor의 생성자를 사용하여 스레드풀의 크기, 작업 큐의 크기, 스레드 생성 정책 등을 설정할 수 있다.
ThreadPoolExecutor executor = new ThreadPoolExecutor(
5, 10, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100));
ForkJoinPool 사용하기: ForkJoinPool은 작업을 작은 단위로 분할하여 병렬로 처리하는 기능을 제공. 이 방법은 병렬 처리가 필요한 경우에 유용!
ForkJoinPool forkJoinPool = new ForkJoinPool();
'의문점 공부하기 > 📌 Java' 카테고리의 다른 글
📌 JSP와 Servlet의 차이점은 !!!? (0) | 2023.08.04 |
---|---|
📌 스레드 풀에서 submit()과 execute()의 차이는 ?!?!? (4) | 2023.08.01 |
📌 thread run()과 thread start()의 차이가 뭘까? (0) | 2023.07.28 |
📌 notify()와 notifyAll()의 차이는 뭘까?! (1) | 2023.07.25 |
📌 sleep()과 wait()의 차이는?!?!? (2) | 2023.07.24 |