|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º ´ÙÀ½ Ŭ·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: NESTED | Çʵå | »ý¼ºÀÚ | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
public interface ExecutorService
Á¾·á¸¦ °ü¸®ÇÏ´Â ¸Þ¼µå ¹× 1°³
ÀÌ»óÀÇ ºñµ¿±â ŽºÅ©ÀÇ ÁøÇà »óȲÀ» ÃßÀûÇÏ´Â Future
¸¦
»ý¼º °¡´ÉÇÑ ¸Þ¼µå¸¦ Á¦°øÇÏ´Â Executor
.
ExecutorService´Â »õ·Î¿î ŽºÅ©ÀÇ ¼ö¶ôÀ» Á¤ÁöÇÏ´Â ¼Ë´Ù¿îÀÌ °¡´ÉÇÕ´Ï´Ù. ¼Ë´Ù¿î Çϸé executor´Â ÃÖÁ¾ÀûÀ¸·Î Á¾·áÇÕ´Ï´Ù¸¸, ±× ½ÃÁ¡¿¡¼´Â ½ÇÇàÁßÀÇ È°¼ºÈµÈ ŽºÅ©³ª ½ÇÇàÀ» ´ë±âÁßÀÇ Å½ºÅ©´Â Á¸ÀçÇÏÁö ¾Ê°í, »õ·Î¿î ŽºÅ©¸¦ ¼Û½ÅÇÒ ¼öµµ ÀÖ½À´Ï´Ù.
submit ¸Þ¼µå´Â ½ÇÇàÀÇ Ãë¼Ò³ª ¿Ï·áÀÇ ´ë±â¿¡ »ç¿ëÇÒ ¼ö ÀÖ´Â Future
¸¦
ÀÛ¼ºÇØ µ¹·ÁÁÖ´Â °ÍÀ¸·Î ±âÀú ¸Þ¼µå Executor.execute(java.lang.Runnable)
¸¦
È®ÀåÇÕ´Ï´Ù. invokeAny ¹× invokeAll ¸Þ¼µå´Â º¸Åë
Æí¸®¼ºÀÇ °¡Àå ³ôÀº Çü½ÄÀÇ ÀÏ°ý ½ÇÇàÀ» ½Ç½ÃÇØ, ŽºÅ©ÀÇ Ä÷º¼ÇÀ» ½ÇÇàÇØ, 1°³
ÀÌ»ó ¶Ç´Â ¸ðµç °ÍÀÌ ¿Ï·áÇÏ´Â °ÍÀ» ´ë±âÇÕ´Ï´Ù. ExecutorCompletionService
Ŭ·¡½º¸¦, ÀÌ·¯ÇÑ ¸Þ¼µåÀÇ Ä¿½ºÅ͸¶ÀÌÁî µÈ º¯ÇüÀÇ Ãâ·Â¿¡ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
Executors
Ŭ·¡½º´Â ÀÌ ÆÐÅ°Áö·Î Á¦°øµÇ´Â executor ¼ºñ½º¿ëÀÇ ÆÑÅ丮 ¸Þ¼µå¸¦ Á¦°øÇÕ´Ï´Ù.
Executors.newFixedThreadPool(int)
ÆÑÅ丮 ¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù.
class NetworkService { private final ServerSocket serverSocket; private final ExecutorService pool; public NetworkService(int port, int poolSize) throws IOException { serverSocket = new ServerSocket(port); pool = Executors.newFixedThreadPool(poolSize); } public void serve() { try { for (;;) { pool.execute(new Handler(serverSocket.accept())); } } catch (IOException ex) { pool.shutdown(); } } } class Handler implements Runnable { private final Socket socket; Handler(Socket socket) { this.socket = socket; } public void run() { // read and service request } }
¸Þ¼µå °³¿ä | ||
---|---|---|
boolean |
awaitTermination (long timeout,
TimeUnit unit)
¼Ë´Ù¿î ¿ä±¸ ÈÄ¿¡ ¸ðµç ŽºÅ©°¡ ½ÇÇàÀ» ¿Ï·áÇϴ ŸÀÓ ¾Æ¿ôÀÌ ¹ß»ýÇÏ´Â ÇöÀçÀÇ thread·Î ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇÏ´Â ¾î¶² °ÍÀΰ¡°¡ ÃÖÃÊ·Î ÀϾ ¶§±îÁö ºí·Ï ÇÕ´Ï´Ù. |
|
|
invokeAll (Collection <Callable <T>> tasks)
ÁöÁ¤µÈ ŽºÅ©¸¦ ½ÇÇàÇØ, Future ¸®½ºÆ®¸¦ ½ºÅ×ÀÌÅͽº¿Í ÇÔ²² µ¹·ÁÁÖ°í, ¸ðµç °ÍÀÌ ¿Ï·áÇÏ¸é °á°ú¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
|
invokeAll (Collection <Callable <T>> tasks,
long timeout,
TimeUnit unit)
ÁöÁ¤µÈ ŽºÅ©¸¦ ½ÇÇàÇØ, Future ¸®½ºÆ®¸¦ ½ºÅ×ÀÌÅͽº¿Í ÇÔ²² µ¹·ÁÁÖ°í, ¸ðµç °ÍÀÌ ¿Ï·áÇϵ簡 ¶Ç´Â ¸¶°¨ ½Ã°£ÀÌ µÉ±îÀÇ ¾ðÁ¨°¡ ºü¸¥ ½ÃÁ¡¿¡¼ °á°ú¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
|
invokeAny (Collection <Callable <T>> tasks)
ÁöÁ¤µÈ ŽºÅ©¸¦ ½ÇÇàÇØ, Á¤»óÀûÀ¸·Î ¿Ï·áÇÑ Å½ºÅ©°¡ Á¸ÀçÇÏ´Â °æ¿ì´Â ±× °á°ú¸¦ (¿¹¿Ü¸¦ Throw ÇÏÁö ¾Ê°í ) ¸®ÅÏÇÕ´Ï´Ù. |
|
|
invokeAny (Collection <Callable <T>> tasks,
long timeout,
TimeUnit unit)
ÁöÁ¤µÈ ŽºÅ©¸¦ ½ÇÇàÇØ, ŸÀÓ ¾Æ¿ôÀÌ µÇ±â Àü¿¡ Á¤»óÀûÀ¸·Î ¿Ï·áÇÑ Å½ºÅ©°¡ Á¸ÀçÇÏ´Â °æ¿ì´Â ±× °á°ú¸¦ (¿¹¿Ü¸¦ Throw ÇÏÁö ¾Ê°í ) ¸®ÅÏÇÕ´Ï´Ù. |
|
boolean |
isShutdown ()
ÀÌ executor°¡ ¼Ë´Ù¿î ÇßÀ» °æ¿ì, true¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
boolean |
isTerminated ()
¼Ë´Ù¿î¿¡ ÀÌ¾î ¸ðµç ŽºÅ©°¡ ¿Ï·áÇßÀ» °æ¿ì¿¡ true¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
void |
shutdown ()
¼ø¼¿¡ µû¶ó ½ÇÇàµÇ´Â ¼Ë´Ù¿îÀ» °³½ÃÇÕ´Ï´Ù. |
|
List <Runnable > |
shutdownNow ()
½ÇÇàÁßÀÇ È°¼ºÈµÈ ŽºÅ© ¸ðµç Á¤Áö¸¦ ½ÃµµÇØ ´ë±âÁßÀÇ Å½ºÅ©ÀÇ Ã³¸®¸¦ Á¤ÁöÇØ, ½ÇÇàÀ» ´ë±âÇÏ°í ÀÖ´ø ŽºÅ©ÀÇ ¸®½ºÆ®¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
|
submit (Callable <T> task)
°ªÀ» µ¹·ÁÁÖ´Â ½ÇÇà ŽºÅ©¸¦ ¼Û½ÅÇØ, º¸·ùÁßÀÇ Å½ºÅ© °á°ú¸¦ ³ªÅ¸³»´Â Future¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
Future <? > |
submit (Runnable task)
½ÇÇà¿ëÀÇ Runnable ŽºÅ©¸¦ ¼Û½ÅÇØ, ±× ŽºÅ©¸¦ ³ªÅ¸³»´Â Future¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
|
|
submit (Runnable task,
T result)
½ÇÇà¿ëÀÇ Runnable ŽºÅ©¸¦ ¼Û½ÅÇØ, ¿Ï·á½Ã·Î ÁöÁ¤µÈ °á°ú¸¦ µ¹·ÁÁִ ŽºÅ©¸¦ ³ªÅ¸³»´Â Future¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
ÀÎÅÍÆäÀ̽º java.util.concurrent. Executor ·ÎºÎÅÍ »ó¼ÓµÈ ¸Þ¼µå |
---|
execute |
¸Þ¼µåÀÇ »ó¼¼ |
---|
void shutdown()
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â »óȲÀ¸·Î ¼Ë´Ù¿îÀ» ½ÇÇàÇϸé, ÀÌ ExecutorService ÀÌ È£ÃâÇØ Ãø¿¡´Â º¯°æÀÌ Çã°¡µÇÁö ¾Ê´Â thread¸¦ Á¶ÀÛÇÒ ¼ö ÀÖ´Â °æ¿ì. ÀÌ°ÍÀº, RuntimePermission
("modifyThread")¸¦ º¸°ü À¯ÁöÇÏÁö ¾Ê´ÂÁö, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkAccess ¸Þ¼µå°¡ ¾×¼¼½º¸¦ °ÅºÎÇϱâ À§ÇØÀÌ´ÙList <Runnable > shutdownNow()
½ÇÇàÁßÀÇ È°¼ºÈµÈ ŽºÅ© 󸮸¦ Á¤ÁöÇϱâ À§Çؼ ÃÖ¼±ÀÇ ³ë·ÂÀ» ÇÏ´Â °Í ÀÌ»óÀÇ º¸ÁõÀº ¾ø½À´Ï´Ù. ¿¹¸¦ µé¾î
º¸Åë
ÀÇ ±¸Çö¿¡¼´Â Thread.interrupt()
¸¦
°³ÀÔ½ÃÄÑ Ãë¼Ò¸¦ Çϱ⠶§¹®¿¡
ŽºÅ©°¡ ÀÎÅÍ·´Æ®¿¡ ´ëÇÑ ÀÀ´äÀ» ¸¶½ºÅ© ÇÏ´ÂÁö ½ÇÆÐÇϸé, ŽºÅ©°¡ Á¾·áÇÏÁö ¾Ê°Ô µÉ °¡´É¼ºÀÌ ÀÖ½À´Ï´Ù.
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â »óȲÀ¸·Î ¼Ë´Ù¿îÀ» ½ÇÇàÇϸé, ÀÌ ExecutorService ÀÌ È£ÃâÇØ Ãø¿¡´Â º¯°æÀÌ Çã°¡µÇÁö ¾Ê´Â thread¸¦ Á¶ÀÛÇÒ ¼ö ÀÖ´Â °æ¿ì. ÀÌ°ÍÀº, RuntimePermission
("modifyThread")¸¦ º¸°ü À¯ÁöÇÏÁö ¾Ê´ÂÁö, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkAccess ¸Þ¼µå°¡ ¾×¼¼½º¸¦ °ÅºÎÇϱâ À§ÇØÀÌ´Ùboolean isShutdown()
boolean isTerminated()
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
timeout
- ´ë±âÇÏ´Â ÃÖÀå ½Ã°£unit
- timeout ÀμöÀÇ ½Ã°£ ´ÜÀ§
InterruptedException
- ´ë±âÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ì<T> Future <T> submit(Callable <T> task)
ŽºÅ©ÀÇ ´ë±â¸¦ Áï½Ã ºí·Ï ÇÏ´Â °æ¿ì´Â result = exec.submit(aCallable). get(); Çü½Ä¿¡¼ ÁöÁ¤ÇÒ ¼ö ÀÖ½À´Ï´Ù.
ÁÖ: Executors
Ŭ·¡½º¿¡´Â Å©·ÎÀ𸦠´àÀº ´Ù¸¥ ÀÏ¹Ý °´Ã¼¸¦ º¯È¯ °¡´ÉÇÑ ¸Þ¼µå ¼¼Æ® (¿¹¸¦ µé¾î, PrivilegedAction
¸¦
¼Û½Å °¡´ÉÇÑ Callable
Çü½ÄÀ¸·Î º¯È¯ÇÒ ¼ö ÀÖ´Ù)°¡ Æ÷ÇԵ˴ϴÙ.
task
- ¼Û½ÅÇϴ ŽºÅ©
RejectedExecutionException
- ŽºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì
NullPointerException
- ŽºÅ©°¡ nullÀÎ °æ¿ì<T> Future <T> submit(Runnable task, T result)
task
- ¼Û½ÅÇϴ ŽºÅ©result
- µ¹·ÁÁÖ´Â °á°ú
RejectedExecutionException
- ŽºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì
NullPointerException
- ŽºÅ©°¡ nullÀÎ °æ¿ìFuture <? > submit(Runnable task)
task
- ¼Û½ÅÇϴ ŽºÅ©
RejectedExecutionException
- ŽºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì
NullPointerException
- ŽºÅ©°¡ nullÀÎ °æ¿ì<T> List <Future <T>> invokeAll(Collection <Callable <T>> tasks) throws InterruptedException
Done
´Â true°¡ µË´Ï´Ù. ¡¸¿Ï·áÇß´Ù¡¹Å½ºÅ©´Â º¸Åë
ÀÇ ¹æ¹ý ¶Ç´Â ¿¹¿Ü¸¦ Throw ÇÏ´Â °ÍÀ¸·Î Á¾·áÇÏ°í ÀÖ½À´Ï´Ù. ÀÌ Á¶ÀÛÀÇ ÁøÇàÁßÀ¸·Î ÁöÁ¤µÈ Ä÷º¼ÇÀÌ º¯°æµÇ¾úÀ» °æ¿ì, ÀÌ ¸Þ¼µåÀÇ °á°ú´Â Á¤ÀǵÇÁö ¾Ê½À´Ï´Ù.
tasks
- ŽºÅ©ÀÇ Ä÷º¼Ç
InterruptedException
- ´ë±âÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ì. ÀÌ °æ¿ì
¹Ì¿Ï·áÀÇ Å½ºÅ©´Â »èÁ¦µÈ´Ù
NullPointerException
- ŽºÅ© ¶Ç´Â ±× ¸î°³ÀÇ ¿ä¼Ò°¡ nullÀÎ °æ¿ì
RejectedExecutionException
- ¸î°³ÀÇ Å½ºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì<T> List <Future <T>> invokeAll(Collection <Callable <T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
Done
´Â true°¡ µË´Ï´Ù. ¸®ÅÏµÈ ½ÃÁ¡¿¡¼´Â ¿Ï·áÇÏ°í ÀÖÁö ¾Ê´Â ŽºÅ©´Â »èÁ¦µË´Ï´Ù. ¡¸¿Ï·áÇß´Ù¡¹Å½ºÅ©´Â º¸Åë
ÀÇ ¹æ¹ý ¶Ç´Â ¿¹¿Ü¸¦ Throw ÇÏ´Â °ÍÀ¸·Î Á¾·áÇÏ°í ÀÖ½À´Ï´Ù. ÀÌ Á¶ÀÛÀÇ ÁøÇàÁßÀ¸·Î ÁöÁ¤µÈ Ä÷º¼ÇÀÌ º¯°æµÇ¾úÀ» °æ¿ì, ÀÌ ¸Þ¼µåÀÇ °á°ú´Â Á¤ÀǵÇÁö ¾Ê½À´Ï´Ù.
tasks
- ŽºÅ©ÀÇ Ä÷º¼Çtimeout
- ´ë±âÇÏ´Â ÃÖÀå ½Ã°£unit
- timeout ÀμöÀÇ ½Ã°£ ´ÜÀ§
InterruptedException
- ´ë±âÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ì. ÀÌ °æ¿ì
¹Ì¿Ï·áÀÇ Å½ºÅ©´Â »èÁ¦µÈ´Ù
NullPointerException
- ŽºÅ©, ±× ¿ä¼ÒÀÇ ¾ðÁ¨°¡ ¶Ç´Â ´ÜÀ§°¡ nullÀÎ °æ¿ì
RejectedExecutionException
- ¸î°³ÀÇ Å½ºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì<T> T invokeAny(Collection <Callable <T>> tasks) throws InterruptedException, ExecutionException
tasks
- ŽºÅ©ÀÇ Ä÷º¼Ç
InterruptedException
- ´ë±âÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ì
NullPointerException
- ŽºÅ© ¶Ç´Â ±× ¸î°³ÀÇ ¿ä¼Ò°¡ nullÀÎ °æ¿ì
IllegalArgumentException
- ŽºÅ©°¡ ºñ¾îÀÖ´Â °æ¿ì
ExecutionException
- Á¤»óÀûÀ¸·Î ¿Ï·áÇÑ Å½ºÅ©°¡ Á¸ÀçÇÏÁö ¾Ê´Â °æ¿ì
RejectedExecutionException
- ŽºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì<T> T invokeAny(Collection <Callable <T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
tasks
- ŽºÅ©ÀÇ Ä÷º¼Çtimeout
- ´ë±âÇÏ´Â ÃÖÀå ½Ã°£unit
- timeout ÀμöÀÇ ½Ã°£ ´ÜÀ§
InterruptedException
- ´ë±âÁß¿¡ ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ì
NullPointerException
- ŽºÅ©, ±× ¿ä¼ÒÀÇ ¾ðÁ¨°¡ ¶Ç´Â ´ÜÀ§°¡ nullÀÎ °æ¿ì
TimeoutException
- ¸î°³ÀÇ Å½ºÅ©°¡ Á¤»óÀûÀ¸·Î ¿Ï·áÇϱâ Àü¿¡
ÁöÁ¤µÈ ŸÀÓ ¾Æ¿ô ½Ã°£ÀÌ °æ°úÇßÀ» °æ¿ì
ExecutionException
- Á¤»óÀûÀ¸·Î ¿Ï·áÇÑ Å½ºÅ©°¡ Á¸ÀçÇÏÁö ¾Ê´Â °æ¿ì
RejectedExecutionException
- ŽºÅ©ÀÇ ½ÇÇàÀ» ½ºÄÉÁÙ ÇÒ ¼ö ¾ø´Â °æ¿ì
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º ´ÙÀ½ Ŭ·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: NESTED | Çʵå | »ý¼ºÀÚ | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy µµ ÂüÁ¶ÇϽʽÿÀ.