Future 와 Callable 그리고 스레드 풀
자바 5 버전
Callable
/**
* A task that returns a result and may throw an exception.
* Implementors define a single method with no arguments called
* {@code call}.
*
* <p>The {@code Callable} interface is similar to {@link
* java.lang.Runnable}, in that both are designed for classes whose
* instances are potentially executed by another thread. A
* {@code Runnable}, however, does not return a result and cannot
* throw a checked exception.
*
* <p>The {@link Executors} class contains utility methods to
* convert from other common forms to {@code Callable} classes.
*
* @see Executor
* @since 1.5
* @author Doug Lea
* @param <V> the result type of method {@code call}
*/
@FunctionalInterface
public interface Callable<V> {
/**
* Computes a result, or throws an exception if unable to do so.
*
* @return computed result
* @throws Exception if unable to compute a result
*/
V call() throws Exception;
}Future
자바 5 에서 제공하는 스레드의 생성과 관리를 위한 스레드 풀

Executor
ExecutorService

ExecuteService 가 지원하는 비동기 작업 기능
ExecutorService 의 작업 종료
ExecutorService 를 확장한 스케줄러
AbstractExecutorService 를 확장한 ThreadPoolExecutor
Executors
newFixedThreadPool
newCachedThreadPool
newScheduledThreadPool
newSingleThreadExecutor
Executors 팩터리 클래스 선택 가이드
스레드풀
목적
이유
Future 의 단점
Last updated