JavaTM Platform
Standard Ed. 6

java.util.concurrent
클래스 Executors

java.lang.Object 
  상위를 확장 java.util.concurrent.Executors


public class Executors
extends Object

이 패키지로 정의된 Executor ,ExecutorService ,ScheduledExecutorService ,ThreadFactory , 및 Callable 클래스용의 팩토리 및 유틸리티 메소드입니다. 이 클래스는, 다음의 종류의 메소드를 지원합니다.

도입된 버젼:
1.5

메소드의 개요
static Callable <Object > callable (PrivilegedAction <? > action)
          호출시에, 지정된 특권 첨부 태스크를 실행해, 그 결과를 돌려주는,Callable 객체를 돌려줍니다.
static Callable <Object > callable (PrivilegedExceptionAction <? > action)
          호출시에, 지정된 특권 첨부 예외 액션을 실행해, 그 결과를 돌려주는,Callable 객체를 돌려줍니다.
static Callable <Object > callable (Runnable  task)
          호출시에, 지정된 태스크를 실행해,null 를 돌려주는,Callable 객체를 돌려줍니다.
static
<T> Callable <T>
callable (Runnable  task, T result)
          호출시에, 지정된 태스크를 실행해, 지정된 결과를 돌려주는,Callable 객체를 돌려줍니다.
static ThreadFactory defaultThreadFactory ()
          신규 thread의 작성에 사용하는 디폴트의 thread 팩토리를 돌려줍니다.
static ExecutorService newCachedThreadPool ()
          필요하게 응해 신규 thread를 작성하는 thread 풀을 작성합니다만, 이용 가능한 경우에는 이전에 구축된 thread를 재사용합니다.
static ExecutorService newCachedThreadPool (ThreadFactory  threadFactory)
          필요하게 응해 신규 thread를 작성하는 thread 풀을 작성합니다만, 이용 가능한 경우에는 이전에 구축된 thread를 재사용합니다.
static ExecutorService newFixedThreadPool (int nThreads)
          공유 안 바운드 형식의 큐없이 동작하는, 고정수의 thread를 재사용하는 thread 풀을 작성합니다.
static ExecutorService newFixedThreadPool (int nThreads, ThreadFactory  threadFactory)
          공유 안 바운드 형식의 큐없이 동작하는, 고정수의 thread를 재사용하는 thread 풀을 작성합니다.
static ScheduledExecutorService newScheduledThreadPool (int corePoolSize)
          지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, thread 풀을 작성합니다.
static ScheduledExecutorService newScheduledThreadPool (int corePoolSize, ThreadFactory  threadFactory)
          지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, thread 풀을 작성합니다.
static ExecutorService newSingleThreadExecutor ()
          안 바운드 형식의 큐없이 동작하는, 단일의 워커 thread를 사용하는 executor 를 작성합니다.
static ExecutorService newSingleThreadExecutor (ThreadFactory  threadFactory)
          안 바운드 형식의 큐없이 동작하는, 단일의 워커 thread를 사용하는 executor 를 작성합니다.
static ScheduledExecutorService newSingleThreadScheduledExecutor ()
          지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, 단일 thread의 executor 를 작성합니다.
static ScheduledExecutorService newSingleThreadScheduledExecutor (ThreadFactory  threadFactory)
          지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, 단일 thread의 executor 를 작성합니다.
static
<T> Callable <T>
privilegedCallable (Callable <T> callable)
          호출시에, 현재의 액세스 제어 문맥으로 지정된 callable 를 실행하는,Callable 객체를 돌려줍니다.
static
<T> Callable <T>
privilegedCallableUsingCurrentClassLoader (Callable <T> callable)
          호출시에, 현재의 액세스 제어 문맥으로, 현재의 문맥 클래스 로더를 콘텍스트 클래스 로더로 하는, 지정된 callable 를 실행하는,Callable 객체를 돌려줍니다.
static ThreadFactory privilegedThreadFactory ()
          현재의 thread와 같은 액세스권을 가지는 신규 thread를 작성하기 위해서 사용하는 thread 팩토리를 돌려줍니다.
static ExecutorService unconfigurableExecutorService (ExecutorService  executor)
          정의 끝난 모든 ExecutorService 메소드가 지정된 executor 에 위양 하지만, 캐스트를 사용해 액세스 가능한 다른 메소드는 위양 하지 않는 객체를 돌려줍니다.
static ScheduledExecutorService unconfigurableScheduledExecutorService (ScheduledExecutorService  executor)
          정의 끝난 모든 ScheduledExecutorService 메소드가 지정된 executor 에 위양 하지만, 캐스트를 사용해 액세스 가능한 다른 메소드는 위양 하지 않는 객체를 돌려줍니다.
 
클래스 java.lang. Object 로부터 상속된 메소드
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait
 

메소드의 상세

newFixedThreadPool

public static ExecutorService  newFixedThreadPool(int nThreads)
공유 안 바운드 형식의 큐없이 동작하는, 고정수의 thread를 재사용하는 thread 풀을 작성합니다. 임의의 포인트로, 최대 nThreads 의 thread가 액티브한 처리 태스크가 됩니다. 모든 thread가 액티브한 경우에, 추가의 태스크가 송신되면(자), 그러한 태스크는 thread가 사용 가능하게 될 때까지 큐로 대기합니다. 실행중에 발생한 장해를 위해서(때문에), 몇개의 thread가 종료전에 종료했을 경우는, 필요에 따라서 신규 thread가 상속해 후속의 태스크를 실행합니다. 명시적인종료 을 할 때까지는, thread는 풀내에 존재합니다.

파라미터:
nThreads - 풀내의 thread수
반환값:
새롭게 작성된 thread 풀
예외:
IllegalArgumentException - nThreads <= 0 의 경우

newFixedThreadPool

public static ExecutorService  newFixedThreadPool(int nThreads,
                                                 ThreadFactory  threadFactory)
공유 안 바운드 형식의 큐없이 동작하는, 고정수의 thread를 재사용하는 thread 풀을 작성합니다. 필요하게 응해 지정된 ThreadFactory 를 사용해 신규 thread를 작성합니다. 임의의 포인트로, 최대 nThreads 의 thread가 액티브한 처리 태스크가 됩니다. 모든 thread가 액티브한 경우에, 추가의 태스크가 송신되면(자), 그러한 태스크는 thread가 사용 가능하게 될 때까지 큐로 대기합니다. 실행중에 발생한 장해를 위해서(때문에), 몇개의 thread가 종료전에 종료했을 경우는, 필요에 따라서 신규 thread가 상속해 후속의 태스크를 실행합니다. 명시적인종료 을 할 때까지는, thread는 풀내에 존재합니다.

파라미터:
nThreads - 풀내의 thread수
threadFactory - 신규 thread의 작성시에 사용하는 팩토리
반환값:
새롭게 작성된 thread 풀
예외:
NullPointerException - threadFactory 가 null 의 경우
IllegalArgumentException - nThreads <= 0 의 경우

newSingleThreadExecutor

public static ExecutorService  newSingleThreadExecutor()
안 바운드 형식의 큐없이 동작하는, 단일의 워커 thread를 사용하는 executor 를 작성합니다. 다만, 실행중에 발생한 장해를 위해서(때문에), 이 단일의 thread가 종료전에 종료했을 경우는, 필요에 따라서 신규 thread가 상속해 후속의 태스크를 실행합니다. 태스크가 차례로 실행되는 것, 및 어느 시점에 있어도 복수의 태스크가 액티브하게 될 것은 없는 것이 보증됩니다. 다른 점으로써 등가인 newFixedThreadPool(1) 과는 달리, 반환되는 executor 에서는 복구성에 의한 추가 thread의 사용은 불가능하다라고 하는 것이 보증되고 있습니다.

반환값:
신규 작성된 단일 thread의 executor

newSingleThreadExecutor

public static ExecutorService  newSingleThreadExecutor(ThreadFactory  threadFactory)
안 바운드 형식의 큐없이 동작하는, 단일의 워커 thread를 사용하는 executor 를 작성합니다. 필요에 따라서, 지정된 ThreadFactory 를 사용해 신규 thread를 작성합니다. 다른 점으로써 등가인 newFixedThreadPool(1, threadFactory) 과는 달리, 반환되는 executor 에서는 복구성에 의한 추가 thread의 사용은 불가능하다라고 하는 것이 보증되고 있습니다.

파라미터:
threadFactory - 신규 thread의 작성시에 사용하는 팩토리
반환값:
신규 작성된 단일 thread의 executor
예외:
NullPointerException - threadFactory 가 null 의 경우

newCachedThreadPool

public static ExecutorService  newCachedThreadPool()
필요하게 응해 신규 thread를 작성하는 thread 풀을 작성합니다만, 이용 가능한 경우에는 이전에 구축된 thread를 재사용합니다. 일반적으로, 이러한 풀은, 단기의 비동기 태스크를 다수 실행하는 프로그램의 퍼포먼스를 개선합니다. execute 를 호출하면(자), 이전에 구축된 thread가 이용 가능하면, 그것을 재사용합니다. 기존의 thread를 사용할 수 없는 경우, 새로운 접속이 작성되어 풀에 추가됩니다. 60 초간 사용되지 않았던 thread는, 종료해, 캐쉬로부터 삭제됩니다. 이 때문에, 오랫동안 IDLE 상태의 풀에 의해 자원이 소비될 것은 없습니다. 유사한 프로퍼티을 가지지만, 상세한 다른 풀 (timeout 파라미터등)은,ThreadPoolExecutor 생성자 을 사용해 작성할 수 있습니다.

반환값:
새롭게 작성된 thread 풀

newCachedThreadPool

public static ExecutorService  newCachedThreadPool(ThreadFactory  threadFactory)
필요하게 응해 신규 thread를 작성하는 thread 풀을 작성합니다만, 이용 가능한 경우에는 이전에 구축된 thread를 재사용합니다. 또, 필요하게 응해 지정된 ThreadFactory 를 사용해 신규 thread를 작성합니다.

파라미터:
threadFactory - 신규 thread의 작성시에 사용하는 팩토리
반환값:
새롭게 작성된 thread 풀
예외:
NullPointerException - threadFactory 가 null 의 경우

newSingleThreadScheduledExecutor

public static ScheduledExecutorService  newSingleThreadScheduledExecutor()
지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, 단일 thread의 executor 를 작성합니다. 다만, 실행중에 발생한 장해를 위해서(때문에), 이 단일의 thread가 종료전에 종료했을 경우는, 필요에 따라서 신규 thread가 상속해 후속의 태스크를 실행합니다. 태스크가 차례로 실행되는 것, 및 어느 시점에 있어도 복수의 태스크가 액티브하게 될 것은 없는 것이 보증됩니다. 다른 점으로써 등가인 newScheduledThreadPool(1) 과는 달리, 반환되는 executor 에서는 복구성에 의한 추가 thread의 사용은 불가능하다라고 하는 것이 보증되고 있습니다.

반환값:
신규 생성된 스케줄 끝난 executor

newSingleThreadScheduledExecutor

public static ScheduledExecutorService  newSingleThreadScheduledExecutor(ThreadFactory  threadFactory)
지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, 단일 thread의 executor 를 작성합니다. 다만, 실행중에 발생한 장해를 위해서(때문에), 이 단일의 thread가 종료전에 종료했을 경우는, 필요에 따라서 신규 thread가 상속해 후속의 태스크를 실행합니다. 태스크가 차례로 실행되는 것, 및 어느 시점에 있어도 복수의 태스크가 액티브하게 될 것은 없는 것이 보증됩니다. 다른 점으로써 등가인 newScheduledThreadPool(1, threadFactory) 과는 달리, 반환되는 executor 에서는 복구성에 의한 추가 thread의 사용은 불가능하다라고 하는 것이 보증되고 있습니다.

파라미터:
threadFactory - 신규 thread의 작성시에 사용하는 팩토리
반환값:
신규 생성된 스케줄 끝난 executor
예외:
NullPointerException - threadFactory 가 null 의 경우

newScheduledThreadPool

public static ScheduledExecutorService  newScheduledThreadPool(int corePoolSize)
지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, thread 풀을 작성합니다.

파라미터:
corePoolSize - 풀내 로 유지하는 thread의 수 (IDLE 상태의 thread도 포함한다)
반환값:
신규 생성된 스케줄 끝난 thread 풀
예외:
IllegalArgumentException - corePoolSize < 0 의 경우

newScheduledThreadPool

public static ScheduledExecutorService  newScheduledThreadPool(int corePoolSize,
                                                              ThreadFactory  threadFactory)
지정된 지연 시간 후, 또는 주기적으로 커멘드의 실행을 스케줄 할 수 있는, thread 풀을 작성합니다.

파라미터:
corePoolSize - 풀내 로 유지하는 thread의 수 (IDLE 상태의 thread도 포함한다)
threadFactory - executor 가 신규 thread를 작성할 때에 사용하는 팩토리
반환값:
신규 생성된 스케줄 끝난 thread 풀
예외:
IllegalArgumentException - corePoolSize < 0 의 경우
NullPointerException - threadFactory 가 null 의 경우

unconfigurableExecutorService

public static ExecutorService  unconfigurableExecutorService(ExecutorService  executor)
정의 끝난 모든 ExecutorService 메소드가 지정된 executor 에 위양 하지만, 캐스트를 사용해 액세스 가능한 다른 메소드는 위양 하지 않는 객체를 돌려줍니다. 이것에 의해, 구성을 안전하게 「freeze」해, 지정된 고유 구현의 튜닝을 허가하지 않게 할 수 있습니다.

파라미터:
executor - 기본으로 되는 구현
반환값:
ExecutorService 인스턴스
예외:
NullPointerException - executor 가 null 의 경우

unconfigurableScheduledExecutorService

public static ScheduledExecutorService  unconfigurableScheduledExecutorService(ScheduledExecutorService  executor)
정의 끝난 모든 ScheduledExecutorService 메소드가 지정된 executor 에 위양 하지만, 캐스트를 사용해 액세스 가능한 다른 메소드는 위양 하지 않는 객체를 돌려줍니다. 이것에 의해, 구성을 안전하게 「freeze」해, 지정된 고유 구현의 튜닝을 허가하지 않게 할 수 있습니다.

파라미터:
executor - 기본으로 되는 구현
반환값:
ScheduledExecutorService 인스턴스
예외:
NullPointerException - executor 가 null 의 경우

defaultThreadFactory

public static ThreadFactory  defaultThreadFactory()
신규 thread의 작성에 사용하는 디폴트의 thread 팩토리를 돌려줍니다. 이 팩토리는, 같은 ThreadGroup 내의 executor 가 사용하는 모든 신규 thread를 작성합니다. SecurityManager 가 존재하는 경우,System.getSecurityManager() 의 그룹이 사용되어 존재하지 않는 경우는 이 defaultThreadFactory 메소드를 호출하는 thread 그룹이 사용됩니다. 각 신규 thread는, 비demon thread로서 작성됩니다. 또, thread의 우선 순위는,Thread.NORM_PRIORITY 또는 thread 그룹의 최고 허용 우선 순위의 언젠가 작은 (분)편으로 설정됩니다. 신규 thread는,pool-N-thread-MThread.getName() 를 개입시켜 액세스 가능한 이름을 가집니다. 여기서,N 는 이 팩토리의 일련 번호,M 는 이 팩토리에 의해 작성된 thread의 일련 번호입니다.

반환값:
thread 팩토리

privilegedThreadFactory

public static ThreadFactory  privilegedThreadFactory()
현재의 thread와 같은 액세스권을 가지는 신규 thread를 작성하기 위해서 사용하는 thread 팩토리를 돌려줍니다. 이 팩토리는,defaultThreadFactory() 와 같은 설정을 가지는 thread를 작성합니다. 또, 신규 thread의 AccessControlContext 및 contextClassLoader 를, 이 privilegedThreadFactory 메소드를 호출하는 thread와 같게 설정합니다. 신규 privilegedThreadFactory 는,AccessController.doPrivileged(java.security.PrivilegedAction) 액션내에서 작성할 수 있습니다. 그 때, 현재의 thread의 액세스 제어 문맥을 설정해, 액션내에 선택한 액세스권 설정을 보관 유지하는 thread를 작성합니다.

이러한 thread내에서 실행중의 태스크는, 현재의 thread와 같은 액세스 제어 및 클래스 로더를 보관 유지합니다만, 같은 ThreadLocalInheritableThreadLocal 치를 보관 유지할 필요는 없습니다. ThreadPoolExecutor.beforeExecute(java.lang.Thread, java.lang.Runnable) 를 사용해 ThreadPoolExecutor 서브 클래스에서 태스크를 실행하기 전에, 필요하게 응해 thread 로컬의 특정의 값을 설정 또는 리셋 할 수 있습니다. 또, 워커 thread를 초기화해, 다른 지정된 thread와 같은 InheritableThreadLocal 설정으로 하는 것이 필요한 경우, 커스텀 ThreadFactory 를 작성해, 내부에서 값을 상속하는 것 외의 thread의 작성의 요구를 thread가 대기 및 처리하도록 할 수 있습니다.

반환값:
thread 팩토리
예외:
AccessControlException - 현재의 액세스 제어 문맥이, 문맥 클래스 로더의 취득과 설정의 양쪽 모두의 액세스권을 보관 유지하지 않는 경우

callable

public static <T> Callable <T> callable(Runnable  task,
                                       T result)
호출시에, 지정된 태스크를 실행해, 지정된 결과를 돌려주는,Callable 객체를 돌려줍니다. 이것은,Callable 를 필요로 하는 메소드를, 다른 방법에서는 결과의 나오지 않는 액션에 적용하는 경우에 도움이 됩니다.

파라미터:
task - 실행하는 태스크
result - 돌려주는 결과
반환값:
호출 가능 객체
예외:
NullPointerException - 태스크가 null 의 경우

callable

public static Callable <Object > callable(Runnable  task)
호출시에, 지정된 태스크를 실행해,null 를 돌려주는,Callable 객체를 돌려줍니다.

파라미터:
task - 실행하는 태스크
반환값:
호출 가능 객체
예외:
NullPointerException - 태스크가 null 의 경우

callable

public static Callable <Object > callable(PrivilegedAction <? > action)
호출시에, 지정된 특권 첨부 태스크를 실행해, 그 결과를 돌려주는,Callable 객체를 돌려줍니다.

파라미터:
action - 실행하는 특권 첨부 액션
반환값:
호출 가능 객체
예외:
NullPointerException - 액션이 null 의 경우

callable

public static Callable <Object > callable(PrivilegedExceptionAction <? > action)
호출시에, 지정된 특권 첨부 예외 액션을 실행해, 그 결과를 돌려주는,Callable 객체를 돌려줍니다.

파라미터:
action - 실행하는 특권 첨부 예외 액션
반환값:
호출 가능 객체
예외:
NullPointerException - 액션이 null 의 경우

privilegedCallable

public static <T> Callable <T> privilegedCallable(Callable <T> callable)
호출시에, 현재의 액세스 제어 문맥으로 지정된 callable 를 실행하는,Callable 객체를 돌려줍니다. 일반적으로, 이 메소드는,AccessController.doPrivileged(java.security.PrivilegedAction) 액션내에서 불려 가 호출 가능 레이아웃을 작성합니다. 호출 가능 레이아웃은, 가능한 경우는 그 액션내에 보관 유지되고 있는 선택한 액세스권 설정에 따라 실행해, 가능하지 않은 경우는 관련지을 수 있었던 AccessControlException 를 throw 합니다.

파라미터:
callable - 기본이 되는 태스크
반환값:
호출 가능 객체
예외:
NullPointerException - 호출 가능 레이아웃이 null 의 경우

privilegedCallableUsingCurrentClassLoader

public static <T> Callable <T> privilegedCallableUsingCurrentClassLoader(Callable <T> callable)
호출시에, 현재의 액세스 제어 문맥으로, 현재의 문맥 클래스 로더를 콘텍스트 클래스 로더로 하는, 지정된 callable 를 실행하는,Callable 객체를 돌려줍니다. 일반적으로, 이 메소드는,AccessController.doPrivileged(java.security.PrivilegedAction) 액션내에서 불려 가 호출 가능 레이아웃을 작성합니다. 호출 가능 레이아웃은, 가능한 경우는 그 액션내에 보관 유지되고 있는 선택한 액세스권 설정에 따라 실행해, 가능하지 않은 경우는 관련지을 수 있었던 AccessControlException 를 throw 합니다.

파라미터:
callable - 기본이 되는 태스크
반환값:
호출 가능 객체
예외:
NullPointerException - 호출 가능 레이아웃이 null 의 경우
AccessControlException - 현재의 액세스 제어 문맥이, 문맥 클래스 로더의 취득과 설정의 양쪽 모두의 액세스권을 보관 유지하지 않는 경우

JavaTM Platform
Standard Ed. 6

버그의 보고와 기능의 요청
한층 더 자세한 API 레퍼런스 및 개발자 문서에 대해서는,Java SE 개발자용 문서를 참조해 주세요. 개발자전용의 상세한 해설, 개념의 개요, 용어의 정의, 버그의 회피책, 및 코드 실례가 포함되어 있습니다.

Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.