|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º Â÷ÀÇ Å¬·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: NESTED | Çʵå | constructor | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
java.lang.Objectjava.lang.Thread
public class Thread
¡¸thread¡¹¶õ ÇÁ·Î±×·¥³»¿¡¼ÀÇ ½ÇÇà threadÀÔ´Ï´Ù. Java °¡»ó ¸Ó½Å¿¡¼´Â ¾îÇø®ÄÉÀ̼ÇÀº º´·Ä¿¡ ½ÇÇàµÇ´Â º¹¼öÀÇ thread¸¦ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù .
°¢ thread¿¡´Â ¿ì¼± ¼øÀ§¸¦ ºÙÀÏ ¼ö ÀÖ°í ÀÖ½À´Ï´Ù. ¿ì¼± ¼øÀ§ÀÇ ³ôÀº thread´Â ¿ì¼± ¼øÀ§ÀÇ ³·Àº threadº¸´Ù ¿ì¼±ÇØ ½ÇÇàµË´Ï´Ù. °Ô´Ù°¡ °¢ thread°¡ demon·Î¼ ¸¶Å© µÇ°í ÀÖ´Â °æ¿ìµµ ÀÖÀ¸¸é, µÇ¾î ÀÖÁö ¾ÊÀº °æ¿ìµµ ÀÖ½À´Ï´Ù. ¾î´À thread·Î ½ÇÇàÁßÀÇ Äڵ尡 »õ·Î¿î Thread
°´Ã¼¸¦ ÀÛ¼ºÇϸé, ÀÌ »õ·Î¿î thread¿¡´Â ±× ½ÃÁ¡¿¡¼´Â ÀÛ¼ºÃøÀÇ threadÀÇ ¿ì¼± ¼øÀ§¿¡ µ¿ÀÏÇÑ ¿ì¼± ¼øÀ§°¡ ¼³Á¤µÇ¾î ÀÛ¼ºÃø thread°¡ demonÀÎ °æ¿ì¿¡¸¸, demon thread.
º¸Åë, Java °¡»ó ¸Ó½ÅÀÌ ½ÃÀÛÇÏ´Â (ÀϹÝÀûÀ¸·Î´Â ÀÖ´Â ÁöÁ¤µÈ Ŭ·¡½ºÀÇ main
¶ó´Â À̸§ÀÌ ºÙÀÏ ¼ö ÀÖ¾ú´ø ¸Þ¼µå¸¦ È£ÃâÇÑ´Ù)¿Í demon thread°¡ ¾Æ´Ñ thread°¡ 1°³
Á¸ÀçÇÕ´Ï´Ù. Java °¡»ó ¸Ó½ÅÀº ¾Æ·¡ÀÇ ¾î¶² °ÍÀΰ¡ÀÇ Á¶°ÇÀÌ ¹ß»ýÇÒ ¶§±îÁö thread¸¦ °è¼Ó ½ÇÇàÇÕ´Ï´Ù.
Runtime
Ŭ·¡½ºÀÇ exit
¸Þ¼µå°¡ ºÒ·Á°¡
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ exit µ¿ÀÛÀ» Çã°¡Çß´Ùrun
¸Þ¼µåÀÇ È£Ãâ·ÎºÎÅÍ º¹±ÍÇÏ´Â °Í¿¡ÀÇÇØ ¶Ç´Â run
¸Þ¼µå Àܷ̿κÎÅÍ º¸³»Áö´Â ¿¹¿Ü¸¦ Throw ÇÏ´Â °Í¿¡ÀÇÇØ demon thread´Â ¾Æ´Ñ ¸ðµç thread°¡ Á¾·áÇß´Ù
»õ·Î¿î ½ÇÇàÀÇ thread¸¦ ÀÛ¼ºÇÏ·Á¸é 2 ¹æ¹ýÀÇ ¹æ¹ýÀÌ ÀÖ½À´Ï´Ù. 1°³ÀÇ ¹æ¹ýÀº Ŭ·¡½º¸¦ Thread
¼ºê Ŭ·¡½ºÀÌ´Ù°í ¼±¾ðÇÏ´Â °ÍÀÔ´Ï´Ù. ÀÌ ¼ºê Ŭ·¡½º´Â Ŭ·¡½º Thread
run
¸Þ¼µå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÏÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù. ±×·¯¸é ¼ºê Ŭ·¡½ºÀÇ ÀνºÅϽº´Â ÇÒ´çÇÒ ¼ö ÀÖ¾î ½ÃÀÛµÉ ¼ö°¡ ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î
ÃʱⰪ
º¸´Ù Å« ¼Ò¼ö¸¦ °è»êÇÏ´Â thread´Â ´ÙÀ½¿¡ ³ªÅ¸³»µµ·Ï
ÀÇÇØ ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù.
class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
´ÙÀ½¿¡ ÀÌÇÏ¿¡ ³ªÅ¸³»´Â ÄÚµå·Î thread¸¦ ÀÛ¼ºÇØ, threadÀÇ ½ÇÇàÀ» °³½ÃÇÕ´Ï´Ù.
PrimeThread p = new PrimeThread(143); p.start();
thread¸¦ ÀÛ¼ºÇÏ´Â ÀÌÁ¦(À̹Ì
) 1°³ÀÇ ¹æ¹ýÀº, Runnable
ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇϴ Ŭ·¡½º¸¦ ¼±¾ðÇÏ´Â °ÍÀÔ´Ï´Ù. ±×·¸´Ù¸é, ±× Ŭ·¡½º´Â run
¸Þ¼µå¸¦ ±¸ÇöÇÕ´Ï´Ù. Ŭ·¡½ºÀÇ ÀνºÅϽº¸¦ ÇÒ´çÇÒ ¼ö ÀÖ¾îThread
ÀÛ¼º½Ã¿¡ Àμö·Î¼ °Ç³×¹Þ¾Æ °³½ÃµË´Ï´Ù. ÀÌ ¹æ¹ý¿¡¼ÀÇ °°Àº ¿¹´Â ÀÌÇÏ¿¡ ³ªÅ¸³»°Ô µË´Ï´Ù.
class PrimeRun implements Runnable { long minPrime; PrimeRun(long minPrime) { this.minPrime = minPrime; } public void run() { // compute primes larger than minPrime . . . } }
´ÙÀ½¿¡ ÀÌÇÏ¿¡ ³ªÅ¸³»´Â ÄÚµå·Î thread¸¦ ÀÛ¼ºÇØ, threadÀÇ ½ÇÇàÀ» °³½ÃÇÕ´Ï´Ù.
PrimeRun p = new PrimeRun(143); new Thread(p). start();
°¢ thread´Â ½Äº°À» À§ÇÑ À̸§À» °¡Áý´Ï´Ù. º¹¼öÀÇ thread°¡ °°Àº À̸§À» °¡Áö´Â ÀÏÀÌ ÀÖ½À´Ï´Ù. threadÀÇ ÀÛ¼º½Ã¿¡ À̸§ÀÌ ÁöÁ¤µÇÁö ¾ÊÀ¸¸é thread¿¡´Â »õ·Î¿î À̸§ÀÌ »ý¼ºµË´Ï´Ù.
Runnable
,
Runtime.exit(int)
,
run()
,
stop()
Áßø(Nested) Ŭ·¡½º °³¿ä | |
---|---|
static class |
Thread.State
thread »óÅÂÀÔ´Ï´Ù. |
static interface |
Thread.UncaughtExceptionHandler
ijġ µÇÁö ¾Ê´Â ¿¹¿Ü¿¡ÀÇÇØ Thread°¡ °©ÀÚ±â Á¾·áÇßÀ» ¶§¿¡ È£ÃâµÇ´Â °Í Çڵ鷯ÀÇ ÀÎÅÍÆäÀ̽ºÀÔ´Ï´Ù. |
ÇÊµå °³¿ä | |
---|---|
static int |
MAX_PRIORITY
thread·Î ¼³Á¤ÇÒ ¼ö ÀÖ´Â ÃÖ°í ¿ì¼± ¼øÀ§ÀÔ´Ï´Ù. |
static int |
MIN_PRIORITY
thread·Î ¼³Á¤ÇÒ ¼ö ÀÖ´Â ÃÖÀú ¿ì¼± ¼øÀ§ÀÔ´Ï´Ù. |
static int |
NORM_PRIORITY
thread¿¡ ÇÒ´çÇÒ ¼ö ÀÖ´Â µðÆúÆ®ÀÇ ¿ì¼± ¼øÀ§ÀÔ´Ï´Ù. |
»ý¼ºÀÚ °³¿ä | |
---|---|
Thread ()
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
|
Thread (Runnable target)
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
|
Thread (Runnable target,
String name)
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
|
Thread (String name)
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
|
Thread (ThreadGroup group,
Runnable target)
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
|
Thread (ThreadGroup group,
Runnable target,
String name)
±× ½ÇÇà °´Ã¼·Î¼ target , À̸§À¸·Î¼ ÁöÁ¤µÈ name ¸¦ °¡Áö´Â group ¿¡ ÀÇÇØ ÂüÁ¶µÇ´Â thread ±×·ì¿¡ ¼ÓÇÏ´Â °Í °°Àº »õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
|
Thread (ThreadGroup group,
Runnable target,
String name,
long stackSize)
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇØ ½ÇÇà °´Ã¼·Î¼ target À»
º¸°ü À¯ÁöÇØ, ÁöÁ¤µÈ name ¸¦ À̸§À¸·Î¼ º¸°ü À¯ÁöÇϵµ·Ï ÇÕ´Ï´Ù. |
|
Thread (ThreadGroup group,
String name)
»õ·Î¿î Thread °´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. |
¸Þ¼µå °³¿ä | |
---|---|
static int |
activeCount ()
ÇöÇà threadÀÇ thread ±×·ì³»ÀÇ È°¼ºÈµÈ thread¼ö¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
void |
checkAccess ()
ÇöÀç ½ÇÇàÁßÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇϱâ À§ÇÑ Á¢±Ù ±ÇÇÑÀ» °¡Áö°í ÀÖÀ»Áö ¾î¶³Áö¸¦ ÆÇÁ¤ÇÕ´Ï´Ù. |
int |
countStackFrames ()
ÃßõÇÏÁö ¾Ê½À´Ï´Ù. ÀÌ È£ÃâÀÇ Á¤ÀÇ´Â Ãßõ µÇÁö ¾Ê´Â suspend() ¿¡
ÀÇÁ¸ÇÕ´Ï´Ù. ¶Ç, ÀÌ È£ÃâÀÇ °á°ú´Â º¸ÁõµÇÁö ¾Ê½À´Ï´Ù. |
static Thread |
currentThread ()
ÇöÀç ½ÇÇàÁßÀÇ thread °´Ã¼ÀÇ ÂüÁ¶¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
void |
destroy ()
ÃßõÇÏÁö ¾Ê½À´Ï´Ù. ÀÌ ¸Þ¼µå´Â ¿ø·¡ Ŭ¸° ¾÷¾øÀÌ ÆÄ±âµÇµµ·Ï ¼³°èµÇ°í ÀÖ¾ú½À´Ï´Ù. º¸°ü À¯ÁöµÇ´Â ¸ð´ÏÅÍ´Â ¶ô µÈ »óŸ¦ À¯ÁöÇÕ´Ï´Ù. ´Ù¸¸, ÀÌ ¸Þ¼µå´Â ±¸ÇöµÇÁö ¾Ê¾Ò½À´Ï´Ù. ±¸ÇöµÇ°í ÀÖÀ¸¸é, suspend() ¿Í
°ÅÀÇ ¶È°°ÀÌ µ¥µå ·ÏÀÌ ¹ß»ýÇÕ´Ï´Ù. Ÿ°Ù thread°¡ Áß¿äÇÑ system resource¸¦ º¸È£ÇÏ´Â ¶ôÀ» º¸°ü À¯ÁöÇÑ »óÅ·ΠÆÄ±âµÇ¾úÀ» °æ¿ì, ¾î´À threadµµ ´Ù½Ã ÀÌ ÀÚ¿ø¿¡ ¾×¼¼½º ÇÒ ¼ö ¾ø½À´Ï´Ù. ´Ù¸¥ thread°¡ ÀÌ ÀÚ¿øÀ» Àá±×·Á°í Çϸé, µ¥µå ·ÏÀÌ ¹ß»ýÇÕ´Ï´Ù. º¸Åë, ±×·¯ÇÑ µ¥µå ·ÏÀº ÀÚ½ÅÀ» ¡¸´Ù¿î ´çÇß´Ù¡¹ÇÁ·Î¼¼½º·Î¼ Ç¥¸íÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ. |
static void |
dumpStack ()
ÇöÀçÀÇ threadÀÇ ½ºÅà Ʈ·¹À̽º¸¦ Ãâ·ÂÇÕ´Ï´Ù. |
static int |
enumerate (Thread [] tarray)
ÇöÇà threadÀÇ thread ±×·ì ¹× ±× ÇÏÀ§ ±×·ì³»ÀÇ ¸ðµç Ȱ¼ºÈµÈ thread¸¦, ÁöÁ¤µÈ ¹è¿¿¡ Ä«ÇÇÇÕ´Ï´Ù. |
static Map <Thread,
StackTraceElement []> |
getAllStackTraces ()
¸ðµç ¶óÀ̺ê threadÀÇ ½ºÅà Ʈ·¹À̽º ¸ÊÀ» ¸®ÅÏÇÕ´Ï´Ù. |
ClassLoader |
getContextClassLoader ()
ÀÌ Thread ÄÁÅØ½ºÆ® ClassLoader¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
static Thread.UncaughtExceptionHandler |
getDefaultUncaughtExceptionHandler ()
ijġ µÇÁö ¾Ê´Â ¿¹¿Ü¿¡ ÀÇÇØ thread°¡ °©ÀÚ±â Á¾·áÇßÀ» ¶§¿¡ È£ÃâµÇ´Â µðÆúÆ®ÀÇ Çڵ鷯¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
long |
getId ()
ÀÌ threadÀÇ ½Äº°ÀÚ¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
String |
getName ()
ÀÌ threadÀÇ À̸§À» ¸®ÅÏÇÕ´Ï´Ù. |
int |
getPriority ()
ÀÌ threadÀÇ ¿ì¼± ¼øÀ§¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
StackTraceElement [] |
getStackTrace ()
ÀÌ threadÀÇ ½ºÅà ´ýÇÁ¸¦ ³ªÅ¸³»´Â ½ºÅà Ʈ·¹À̽º ¿ä¼ÒÀÇ ¹è¿À» ¸®ÅÏÇÕ´Ï´Ù. |
Thread.State |
getState ()
ÀÌ thread »óŸ¦ ¸®ÅÏÇÕ´Ï´Ù. |
ThreadGroup |
getThreadGroup ()
ÀÌ thread°¡ ¼Ò¼ÓÇÏ´Â thread ±×·ìÀ» ¸®ÅÏÇÕ´Ï´Ù. |
Thread.UncaughtExceptionHandler |
getUncaughtExceptionHandler ()
ijġ µÇÁö ¾Ê´Â ¿¹¿Ü¿¡ ÀÇÇØ thread°¡ °©ÀÚ±â Á¾·áÇßÀ» ¶§¿¡ È£ÃâµÇ´Â Çڵ鷯¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
static boolean |
holdsLock (Object obj)
ÇöÇà thread°¡ ÁöÁ¤µÈ °´Ã¼¿¡ ´ëÇÑ ¸ð´ÏÅÍ ¶ôÀ» º¸°ü À¯ÁöÇÏ´Â °æ¿ì¿¡°Ô¸¸, true¸¦ ¸®ÅÏÇÕ´Ï´Ù. |
void |
interrupt ()
ÀÌ thread¿¡ ³¢¾îµì´Ï´Ù. |
static boolean |
interrupted ()
ÇöÀçÀÇ thread°¡ ³¢¾îµé¾îÁö°í ÀÖ´ÂÁö¸¦ Á¶»çÇÕ´Ï´Ù. |
boolean |
isAlive ()
ÀÌ thread°¡ »ýÁ¸Çϰí ÀÖÀ»Áö ¾î¶³Áö¸¦ ÆÇÁ¤ÇÕ´Ï´Ù. |
boolean |
isDaemon ()
ÀÌ thread°¡ demon threadÀÏÁö ¾î¶³Áö¸¦ ÆÇÁ¤ÇÕ´Ï´Ù. |
boolean |
isInterrupted ()
ÀÌ thread°¡ ³¢¾îµé¾îÁö°í ÀÖ´Â Á¦¹ßÀ» Á¶»çÇÕ´Ï´Ù. |
void |
join ()
ÀÌ thread°¡ Á¾·áÇÏ´Â °ÍÀ» ´ë±âÇÕ´Ï´Ù. |
void |
join (long millis)
ÀÌ thread°¡ Á¾·áÇÏ´Â °ÍÀ» ÃÖ°í·Î millis ¹Ð¸® ¼¼ÄÁµå ´ë±âÇÕ´Ï´Ù. |
void |
join (long millis,
int nanos)
ÃÖ°í·Î millis ¹Ð¸® ¼¼ÄÁµå¿¡ nanos ³ª³ëÃʸ¦ °¡»êÇÑ »çÀÌ, ÀÌ thread°¡ Á¾·áÇÏ´Â °ÍÀ» ´ë±âÇÕ´Ï´Ù. |
void |
resume ()
ÃßõÇÏÁö ¾Ê½À´Ï´Ù. ÀÌ ¸Þ¼µå´Â µ¥µå ·ÏÀ» ¹ß»ýÇϱ⠽±±â ¶§¹®¿¡ Ãßõ µÇÁö ¾Ê½À´Ï´Ù. suspend() ¿Í
ÇÔ²² »ç¿ëÇϱâ À§ÇØÀÎ ¸¸Å Á¦°øµÇ°í ÀÖ½À´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ. |
void |
run ()
ÀÌ thread°¡ º°°³ÀÇ Runnable ½ÇÇà °´Ã¼¸¦ »ç¿ëÇØ ÀÛ¼ºµÇ¾úÀ» °æ¿ì, ±× Runnable °´Ã¼ÀÇ run ¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. |
void |
setContextClassLoader (ClassLoader cl)
ÀÌ Thread ÄÁÅØ½ºÆ® ClassLoader¸¦ ¼³Á¤ÇÕ´Ï´Ù. |
void |
setDaemon (boolean on)
ÀÌ thread¸¦, demon thread ¶Ç´Â »ç¿ëÀÚ thread·Î¼ ¸¶Å© ÇÕ´Ï´Ù. |
static void |
setDefaultUncaughtExceptionHandler (Thread.UncaughtExceptionHandler eh)
ijġ µÇÁö ¾Ê´Â ¿¹¿Ü¿¡ÀÇÇØ thread°¡ °©ÀÚ±â Á¾·áÇßÀ» ¶§³ª, ÀÌ thread¿¡ ´ëÇØ¼ ±× ¹Û¿¡ Çڵ鷯°¡ Á¤ÀǵǾî ÀÖÁö ¾ÊÀ» ¶§¿¡ È£ÃâµÇ´Â µðÆúÆ®ÀÇ Çڵ鷯¸¦ ¼³Á¤ÇÕ´Ï´Ù. |
void |
setName (String name)
ÀÌ threadÀÇ À̸§À» Àμö name ¿¡ µ¿ÀÏÇØÁöµµ·Ï º¯°æÇÕ´Ï´Ù. |
void |
setPriority (int newPriority)
ÀÌ threadÀÇ ¿ì¼± ¼øÀ§¸¦ º¯°æÇÕ´Ï´Ù. |
void |
setUncaughtExceptionHandler (Thread.UncaughtExceptionHandler eh)
ijġ µÇÁö ¾Ê´Â ¿¹¿Ü¿¡ÀÇÇØ °©ÀÚ±â thread°¡ Á¾·áÇßÀ» ¶§¿¡ »ç¿ëµÇ´Â Çڵ鷯¸¦ ¼³Á¤ÇÕ´Ï´Ù. |
static void |
sleep (long millis)
ÇöÀç ½ÇÇàÁßÀÇ thread¸¦, ÁöÁ¤µÈ ¹Ð¸® ¼¼ÄÁµå¼öÀÇ »çÀÌ, sleeve (ÀϽÃÀûÀ¸·Î ½ÇÇàÀ» Á¤Áö) ½Ãŵ´Ï´Ù. |
static void |
sleep (long millis,
int nanos)
ÇöÀç ½ÇÇàÁßÀÇ thread¸¦, ÁöÁ¤µÈ ¹Ð¸® ¼¼ÄÁµå¼ö·Î ÁöÁ¤µÈ ³ª³ëÃʼö¸¦ °¡»êÇÑ »çÀÌ, sleeve (½ÇÇà Á¤Áö) ½Ãŵ´Ï´Ù. |
void |
start ()
ÀÌ threadÀÇ ½ÇÇàÀ» °³½ÃÇÕ´Ï´Ù. |
void |
stop ()
ÃßõÇÏÁö ¾Ê½À´Ï´Ù. ÀÌ ¸Þ¼µå´Â º»ÁúÀûÀ¸·Î ¾ÈÀüÇÏÁö´Â ¾Ê½À´Ï´Ù. Thread.stop¸¦ »ç¿ëÇØ thread¸¦ Á¤ÁöÇϸé, üũµÇ¾î ÀÖÁö ¾ÊÀº ThreadDeath ¿¹¿Ü°¡ ½ºÅþƷ¡¿¡¼ À§¿¡°Ô ÀüÇÒ ¼ö ÀÖ¾ú´ø °á°ú, ±× thread¿¡ ÀÇÇØ ¶ô µÇ°í ÀÖ´ø ¸ð´ÏÅÍÀÇ ¶ôÀÌ ¸ðµÎ ÇØÁ¦µË´Ï´Ù. ÀÌ·¯ÇÑ ¸ð´ÏÅÍ¿¡ ÀÇÇØ Á÷Àü±îÁö º¸È£µÇ°í ÀÖ´ø °´Ã¼°¡ Á¤ÇÕ¼ºÀÇ ¾ø´Â »óÅ¿¡ ÀÖ¾úÀ» °æ¿ì, ¸Á°¡Áø °´Ã¼´Â ´Ù¸¥ thread¿¡ ´ëÇØ¼ °¡½Ã°¡ µÇ¾î, µ¿ÀÛÀÌ º¸ÁõµÇÁö ¾Ê´Â °ÍÀÌ ÀÖ½À´Ï´Ù. ¸¹Àº °æ¿ì, Ÿ°Ù threadÀÇ ½ÇÇà Á¤Áö¸¦ Áö½ÃÇÏ·Á¸é,
stop ´Â ¾Æ´Ï°í, ´ÜÁö ÀϺÎÀÇ º¯¼ö¸¦ º¯°æÇÏ´Â Äڵ带 »ç¿ëÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù. Ÿ°Ù thread´Â ÀÌ º¯¼ö¸¦ Á¤±âÀûÀ¸·Î Ã¼Å©ÇØ, º¯¼ö°¡ ½ÇÇà Á¤Áö¸¦ Áö½ÃÇϰí ÀÖ´Â °æ¿ì´Â run ¸Þ¼µå·ÎºÎÅÍ ÀûÀýÈ÷ º¹±ÍÇÕ´Ï´Ù. Á¶°Ç º¯¼öµîÀ¸·Î Ÿ°Ù thread°¡ ¿À·§µ¿¾È ´ë±âÇϰí ÀÖ´Â °æ¿ì, ´ë±â¸¦ ÁߴܽÃŰ·Á¸é,
interrupt ¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ. |
void |
stop (Throwable obj)
ÃßõÇÏÁö ¾Ê½À´Ï´Ù. ÀÌ ¸Þ¼µå´Â º»ÁúÀûÀ¸·Î ¾ÈÀüÇÏÁö´Â ¾Ê½À´Ï´Ù. stop() ¸¦
ÂüÁ¶ÇϽʽÿÀ. °Ô´Ù°¡ ÀÌ ¸Þ¼µå´Â Ÿ°Ù thread·Î ó¸®ÀÇ Áغñ°¡ µÇ¾î ÀÖÁö ¾ÊÀº ¿¹¿ÜÀÇ »ý¼º¿¡ »ç¿ëµÇ´Â ÀÏÀÌ ÀÖ´Â Á¡¿¡¼µµ À§ÇèÇÕ´Ï´Ù (ÀÌ ¸Þ¼µå°¡ ¾øÀ¸¸é thread¿¡ ÀÇÇØ Throw µÉ¸®°¡ ¾ø´Â üũµÈ ¿¹¿Ü µî). ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ. |
void |
suspend ()
ÃßõÇÏÁö ¾Ê½À´Ï´Ù. ÀÌ ¸Þ¼µå´Â µ¥µå ·ÏÀ» ¹ß»ýÇϱ⠽±±â ¶§¹®¿¡ Ãßõ µÇÁö ¾Ê½À´Ï´Ù. Ÿ°Ù thread°¡ Áß¿äÇÑ system resource¸¦ º¸È£Çϰí ÀÖ´Â ¸ð´ÏÅÍÀÇ ¶ôÀ» º¸°ü À¯ÁöÇϰí ÀÖ´Â »óÅ·ΠÁߴܵǾúÀ» °æ¿ì, Ÿ°Ù thread°¡ Àç°³µÉ ¶§±îÁö, ¾î´À threadµµ ÀÌ ÀÚ¿ø¿¡ ¾×¼¼½º ÇÒ ¼ö ¾ø½À´Ï´Ù. Ÿ°Ù thread¸¦ Àç°³ÇÏ·Á°í ÇÏ´Â thread°¡ resume ¸¦ È£ÃâÇϱâ Àü¿¡ ÀÌ ¸ð´ÏÅ͸¦ Àá±×·Á°í Çϸé, µ¥µå ·ÏÀÌ ¹ß»ýÇÕ´Ï´Ù. º¸Åë, ±×·¯ÇÑ µ¥µå ·ÏÀº ÀÚ½ÅÀ» ¡¸´Ù¿î ´çÇß´Ù¡¹ÇÁ·Î¼¼½º·Î¼ Ç¥¸íÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ. |
String |
toString ()
threadÀÇ À̸§, ¿ì¼± ¼øÀ§, thread ±×·ìÀ» Æ÷ÇÔÇÑ ÀÌ threadÀÇ Ä³¸¯ÅÍ ¶óÀΠǥÇöÀ» ¸®ÅÏÇÕ´Ï´Ù. |
static void |
yield ()
ÇöÀç ½ÇÇàÁßÀÇ thread °´Ã¼¸¦ ÀϽÃÀûÀ¸·Î ÈÞÁö½ÃÄÑ, ´Ù¸¥ thread¸¦ ½ÇÇàÇÒ ¼ö ÀÖµµ·Ï ÇÕ´Ï´Ù. |
Ŭ·¡½º java.lang. Object ·ÎºÎÅÍ »ó¼ÓµÈ ¸Þ¼µå |
---|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
ÇʵåÀÇ »ó¼¼ |
---|
public static final int MIN_PRIORITY
public static final int NORM_PRIORITY
public static final int MAX_PRIORITY
»ý¼ºÀÚ »ó¼¼ |
---|
public Thread()
Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. ÀÌ »ý¼ºÀÚ´Â Thread(null, null,
gname)
¿Í
°°Àº È¿°ú¸¦ °¡Áý´Ï´Ù. ÀÌ °æ¿ì
gname´Â
»õ·Ó°Ô ÀÛ¼ºµÇ´Â À̸§ÀÔ´Ï´Ù. ÀÚµ¿ÀûÀ¸·Î ÀÛ¼ºµÇ´Â À̸§Àº, n¸¦ Á¤¼ö·Î Çϸé "Thread-"+
n
Çü½ÄÀ» ÃëÇÕ´Ï´Ù.
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
public Thread(Runnable target)
Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. ÀÌ »ý¼ºÀÚ´Â Thread(null, target,
gname)
¿Í
°°Àº È¿°ú¸¦ °¡Áý´Ï´Ù. ÀÌ °æ¿ì
gname´Â
»õ·Ó°Ô ÀÛ¼ºµÇ´Â À̸§ÀÔ´Ï´Ù. ÀÚµ¿ÀûÀ¸·Î ÀÛ¼ºµÇ´Â À̸§Àº, n¸¦ Á¤¼ö·Î Çϸé "Thread-"+
n
Çü½ÄÀ» ÃëÇÕ´Ï´Ù.
target
- ±× run
¸Þ¼µå°¡ È£ÃâµÇ´Â °´Ã¼Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
public Thread(ThreadGroup group, Runnable target)
Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. ÀÌ »ý¼ºÀÚ´Â Thread(group, target,
gname)
¿Í
°°Àº È¿°ú¸¦ °¡Áý´Ï´Ù. ÀÌ °æ¿ì
gname´Â
»õ·Ó°Ô ÀÛ¼ºµÇ´Â À̸§ÀÔ´Ï´Ù. ÀÚµ¿ÀûÀ¸·Î ÀÛ¼ºµÇ´Â À̸§Àº, n¸¦ Á¤¼ö·Î Çϸé "Thread-"+
n
Çü½ÄÀ» ÃëÇÕ´Ï´Ù.
group
- thread ±×·ìtarget
- ±× run
¸Þ¼µå°¡ È£ÃâµÇ´Â °´Ã¼
SecurityException
- ÇöÀçÀÇ thread°¡ ÁöÁ¤µÈ thread ±×·ì³»¿¡ thread¸¦ ÀÛ¼ºÇÒ ¼ö ¾ø´Â °æ¿ìThread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
public Thread(String name)
Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. ÀÌ »ý¼ºÀÚ´Â Thread(null, null, name)
¿Í
°°Àº È¿°ú¸¦ °¡Áý´Ï´Ù.
name
- »õ·Î¿î threadÀÇ À̸§Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
public Thread(ThreadGroup group, String name)
Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. ÀÌ »ý¼ºÀÚ´Â Thread(group, null, name)
¿Í
°°Àº È¿°ú¸¦ °¡Áý´Ï´Ù.
group
- thread ±×·ìname
- »õ·Î¿î threadÀÇ À̸§
SecurityException
- ÇöÀçÀÇ thread°¡ ÁöÁ¤µÈ thread ±×·ì³»¿¡ thread¸¦ ÀÛ¼ºÇÒ ¼ö ¾ø´Â °æ¿ìThread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
public Thread(Runnable target, String name)
Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù. ÀÌ »ý¼ºÀÚ´Â Thread(null, target, name)
¿Í
°°Àº È¿°ú¸¦ °¡Áý´Ï´Ù.
target
- ±× run
¸Þ¼µå°¡ È£ÃâµÇ´Â °´Ã¼name
- »õ·Î¿î threadÀÇ À̸§Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
public Thread(ThreadGroup group, Runnable target, String name)
target
, À̸§À¸·Î¼ ÁöÁ¤µÈ name
¸¦ °¡Áö´Â group
¿¡ ÀÇÇØ ÂüÁ¶µÇ´Â thread ±×·ì¿¡ ¼ÓÇÏ´Â °Í °°Àº »õ·Î¿î Thread
°´Ã¼¸¦ ÇÒ´çÇÕ´Ï´Ù.
group
°¡ null
·Î
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â °æ¿ì, ±×·ìÀº ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ getThreadGroup
¸Þ¼µå¿¡ ÀÇÇØ Á¤ÇØÁý´Ï´Ù. group
°¡ null
·Î
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏÁö ¾Ê´Â °æ¿ì, ¶Ç´Â ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ getThreadGroup
¸Þ¼µå°¡ null
À»
µ¹·ÁÁÖ´Â °æ¿ì, ±×·ìÀº »õ·Î¿î thread¸¦ ÀÛ¼ºÁßÀÇ thread¿Í °°Àº ThreadGroup ·Î ¼³Á¤µË´Ï´Ù.
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â °æ¿ì´Â ThreadGroup¸¦ Àμö·Î¼ °Ç³×ÁÖ¾î checkAccess
¸Þ¼µå¸¦ È£ÃâÇÕ´Ï´Ù.
¶Ç, getContextClassLoader
¸Þ¼µå ¶Ç´Â setContextClassLoader
¸Þ¼µå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÏ´Â ¼ºê Ŭ·¡½ºÀÇ »ý¼ºÀÚ¿¡ ÀÇÇØ Á÷Á¢Àû ¶Ç´Â °£Á¢ÀûÀ¸·Î ºÒ·Á °¬À» ¶§, RuntimePermission("enableContextClassLoaderOverride")
Á¢±Ù ±ÇÇÑÀ» »ç¿ëÇØ checkPermission
¸Þ¼µå¸¦ È£ÃâÇÕ´Ï´Ù. ±× °á°ú, SecurityException°¡ ¹ß»ýÇÏ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
target
Àμö°¡ null
ÀÌ ¾Æ´Ñ °æ¿ì, ÀÌ thread°¡ ½ÃÀ۵Ǹé target
run
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. target Àμö°¡ null
ÀÎ °æ¿ì´Â ÀÌ thread°¡ ½ÃÀÛµÉ ¶§ ÀÌ threadÀÇ run
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù.
»õ·Ó°Ô ÀÛ¼ºµÈ threadÀÇ ¿ì¼± ¼øÀ§´Â ±× thread¸¦ ÀÛ¼ºÇÑ thread, Áï ÇöÀç ½ÇÇàÁßÀÇ threadÀÇ ¿ì¼± ¼øÀ§¿Í °°°Ô ¼³Á¤µË´Ï´Ù. ÀÌ ¿ì¼± ¼øÀ§¸¦ »õ·Î¿î °ªÀ¸·Î º¯°æÇÏ´Â °æ¿ì´Â ¸Þ¼µå setPriority
¸¦ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
»õ·Ó°Ô ÀÛ¼ºµÈ thread´Â ±×°ÍÀ» ÀÛ¼ºÇÏ´Â thread°¡ demon thread¿Í ¸¶Å© µÇ°í ÀÖ´Â °æ¿ì¿¡¸¸, demon thread¿Í ¸¶Å© µË´Ï´Ù. thread°¡ demonÀÏÁö ¾î¶³Áö¸¦ º¯°æÇÏ´Â °æ¿ì´Â ¸Þ¼µå setDaemon
À»
»ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
group
- thread ±×·ìtarget
- ±× run
¸Þ¼µå°¡ È£ÃâµÇ´Â °´Ã¼name
- »õ·Î¿î threadÀÇ À̸§
SecurityException
- ÇöÀçÀÇ thread°¡ ÁöÁ¤µÈ thread ±×·ì³»¿¡ thread¸¦ ÀÛ¼ºÇÒ ¼ö ¾ø´Â ¶Ç´Â ÄÁÅØ½ºÆ®
Ŭ·¡½º ·Î´õÀÇ ¸Þ¼µå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÒ ¼ö ¾ø´Â °æ¿ìRunnable.run()
,
run()
,
setDaemon(boolean)
,
setPriority(int)
,
ThreadGroup.checkAccess()
,
SecurityManager.checkAccess(java.lang.Thread)
public Thread(ThreadGroup group, Runnable target, String name, long stackSize)
Thread
°´Ã¼¸¦ ÇÒ´çÇØ ½ÇÇà °´Ã¼·Î¼ target
À»
º¸°ü À¯ÁöÇØ, ÁöÁ¤µÈ name
¸¦ À̸§À¸·Î¼ º¸°ü À¯ÁöÇϵµ·Ï ÇÕ´Ï´Ù. ¶Ç, group
¿¡ ÀÇÇØ ÂüÁ¶µÇ´Â thread ±×·ì¿¡ ¼Ò¼ÓÇØ, ÁöÁ¤µÈ ¡¸½ºÅà »çÀÌÁ¸¦ º¸°ü À¯ÁöÇÕ´Ï´Ù.
ÀÌ »ý¼ºÀÚ´Â threadÀÇ ½ºÅà »çÀÌÁî ÁöÁ¤ÀÌ °¡´ÉÇÑ Á¡À» Á¦¿ÜÇØ, Thread(ThreadGroup, Runnable, String)
¿Í
°°½À´Ï´Ù. ½ºÅà »çÀÌÁî´Â °¡»ó ¸Ó½ÅÀ» ÀÌ threadÀÇ ½ºÅÿ¡ ÇÒ´çÇÏ´Â address °ø°£ÀÇ ´ë·«ÀÇ ¹ÙÀÌÆ®¼ö°¡ µË´Ï´Ù. stackSize ÆÄ¶ó¹ÌÅͰ¡ Á¸ÀçÇÏ´Â °æ¿ì, ±× È¿°ú´Â Ç÷§Æû¿¡ ÀÇÇØ Å©°Ô ´Ù¸¨´Ï´Ù.
¸î°³ÀÇ Ç÷§Æû¿¡¼´Â stackSize ÆÄ¶ó¹ÌÅÍ¿¡ ÀÇÇØ Å« °ªÀ» ÁöÁ¤ÇÏ´Â °ÍÀ¸·Î thread°¡ StackOverflowError
¸¦
Throw Çϱâ Àü¿¡ ÀÇÇØ Å« ȸ±Í ½Éµµ¸¦ ´Þ¼ºÇÏ´Â °ÍÀÌ °¡´ÉÇÏ°Ô µË´Ï´Ù. °°À̺¸´Ù ÀÛÀº °ªÀ» ÁöÁ¤ÇÏ´Â °ÍÀ¸·Î º¸´Ù ¸¹Àº thread°¡ OutOfMemoryError
(¶Ç´Â ´Ù¸¥ ³»ºÎ ¿¡·¯)¸¦ Throw ÇÏÁö ¾Ê°í,
µ¿½Ã¿¡ Á¸ÀçÇÏ´Â °ÍÀÌ °¡´ÉÇÏ°Ô µË´Ï´Ù. stackSize ÆÄ¶ó¹ÌÅÍÀÇ °ª°ú ÃÖ´ë ȸ±Í ½Éµµ³ª º´Çà ·¹º§°úÀÇ °ü°è´Â Ç÷§Æû¿¡ µû¶ó¼ ´Ù¸¨´Ï´Ù. Ç÷§Æû¿¡ µû¶ó¼´Â stackSize ÆÄ¶ó¹ÌÅÍÀÇ °ªÀÌ ¾î¶² ¿µÇâÀ» ÁÖÁö ¾Ê´Â °æ¿ì°¡ ÀÖ½À´Ï´Ù.
°¡»ó ¸Ó½ÅÀº, stackSize ÆÄ¶ó¹ÌÅ͸¦ ÀÚÀ¯·Ó°Ô Ãë±ÞÇØ, Áö½ÃÇÒ ¼ö ÀÖ½À´Ï´Ù . Ç÷§Æû¿¡¼´Â ÁöÁ¤µÈ °ªÀÌ ³Ê¹« ÀÛÀº °æ¿ì, °¡»ó ¸Ó½ÅÀº ´ë½Å¿¡ Ç÷§Æû °íÀ¯ÀÇ ÃÖ¼Ò°ªÀ» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ÁöÁ¤µÈ °ªÀÌ ³Ê¹« Å« °æ¿ì¿¡´Â °¡»ó ¸Ó½ÅÀº ´ë½Å¿¡ Ç÷§Æû °íÀ¯ÀÇ ÃÖ´ë°ªÀ» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. °°ÀÌ °¡»ó ¸Ó½ÅÀº ÀûÀýÇÑ °æ¿ì¿¡´Â ÁöÁ¤µÈ °ªÀÇ Àý»óÇØ ¶Ç´Â ÀÎÇϸ¦ ÀÚÀ¯·Ó°Ô ½ÇÇà (¶Ç´Â ¿ÏÀüÇÏ°Ô ¹«½Ã)ÇÒ ¼ö ÀÖ½À´Ï´Ù.
stackSize ÆÄ¶ó¹ÌÅÍ¿¡ °ªÁ¦·Î¸¦ ÁöÁ¤Çϸé, ÀÌ »ý¼ºÀÚ´Â Thread(ThreadGroup, Runnable, String) »ý¼ºÀÚ°ú Á¤È®ÇÏ°Ô °°Àº µ¿ÀÛÀ» ½ÇÇàÇÕ´Ï´Ù.
ÀÌ »ý¼ºÀÚ µ¿ÀÛÀº Ç÷§Æû¿¡ µû¶ó¼ ´Ù¸£±â À§Çؼ ½ÅÁßÇÏ°Ô »ç¿ëÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù. ÁöÁ¤µÈ °è»êÀÇ ½ÇÇà¿¡ ÇÊ¿äÇÑ thread ½ºÅà »çÀÌÁî´Â JRE ±¸Çö¿¡ µû¶ó¼ ´Ù¸¦ °¡´É¼ºÀÌ ÀÖ½À´Ï´Ù. ÀÌ ¶§¹®¿¡ ½ºÅà »çÀÌÁî ÆÄ¶ó¹ÌÅ͸¦ ÁÖÀÇ ±í°Ô Æ©´× Çϰųª ¾îÇø®ÄÉÀ̼ÇÀ» ½ÇÇàÇÏ´Â JRE ±¸Çö ¸¶´Ù Æ©´×À» ¹Ýº¹Çϰųª ÇÏ´Â °ÍÀÌ ÇÊ¿äÇÑ °æ¿ì°¡ ÀÖ½À´Ï´Ù.
±¸Çö»óÀÇ ÁÖÀÇÁ¡: Java Ç÷§Æû ±¸ÇöÀÚ´Â stackSize parameter¸¦ ±âÁØÀ¸·ÎÀÇÇØ ±¸ÇöÀÇ µ¿ÀÛÀ» ¹®¼ÈÇØ µÎ´Â °ÍÀ» ÃßõÇÕ´Ï´Ù.
group
- thread ±×·ìtarget
- ±× run
¸Þ¼µå°¡ È£ÃâµÇ´Â °´Ã¼name
- »õ·Î¿î threadÀÇ À̸§stackSize
- »õ·Î¿î threadÀÇ ½ºÅà »çÀÌÁî ¶Ç´Â Á¦·Î (ÀÌ ÆÄ¶ó¹ÌÅ͸¦ ¹«½ÃÇÏ´Â °ÍÀ» ³ªÅ¸³½´Ù)
SecurityException
- ÇöÀçÀÇ thread°¡ ÁöÁ¤µÈ thread ±×·ì³»¿¡ thread¸¦ ÀÛ¼ºÇÒ ¼ö ¾ø´Â °æ¿ì¸Þ¼µåÀÇ »ó¼¼ |
---|
public static Thread currentThread()
public static void yield()
public static void sleep(long millis) throws InterruptedException
millis
- ¹Ð¸® ¼¼ÄÁµå ´ÜÀ§ÀÇ sleeve ½Ã°£ÀÇ ±æÀÌ
InterruptedException
- º°ÀÇ thread°¡ ÇöÀçÀÇ thread¿¡ ³¢¾îµé¾úÀ» °æ¿ì. ÀÌ ¿¹¿Ü°¡ Throw µÇ¸é, ÇöÀçÀÇ threadÀÇ ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº´Â Ŭ¸®¾î µÇ´ÂObject.notify()
public static void sleep(long millis, int nanos) throws InterruptedException
millis
- ¹Ð¸® ¼¼ÄÁµå ´ÜÀ§ÀÇ sleeve ½Ã°£ÀÇ ±æÀÌnanos
- sleeveÇϱâ À§ÇÑ 0 ~ 999999
Ãß°¡ ³ª³ëÃÊ
IllegalArgumentException
- millis
°ªÀÌ À½¼öÀÇ °æ¿ì, ¶Ç´Â nanos
°ªÀÌ 0 ~ 999999
¹üÀ§¿ÜÀÇ °æ¿ì
InterruptedException
- º°ÀÇ thread°¡ ÇöÀçÀÇ thread¿¡ ³¢¾îµé¾úÀ» °æ¿ì. ÀÌ ¿¹¿Ü°¡ Throw µÇ¸é, ÇöÀçÀÇ threadÀÇ ¡¸ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº¡¹´Â Ŭ¸®¾î µÇ´ÂObject.notify()
public void start()
run
¸Þ¼µå¸¦ È£ÃâÇÕ´Ï´Ù.
±× °á°ú, (start
¸Þ¼µå¿¡ÀÇ È£Ãâ·ÎºÎÅÍ º¹±ÍÇÑ´Ù) ÇöÀçÀÇ thread¿Í (±× run
¸Þ¼µå¸¦ ½ÇÇàÇÑ´Ù) ´Ù¸¥ thread¶ó°í ÇÏ´Â 2°³ÀÇ thread°¡ º´·Ä¿¡ ½ÇÇàµË´Ï´Ù.
thread¸¦ ¿©·¯ Â÷·Ê ½ÃÀÛÇÏ´Â °ÍÀº °áÄÚ ¿Ã¹Ù¸£´Ù°í´Â ¸»ÇÒ ¼ö ¾ø½À´Ï´Ù. ƯÈ÷, thread´Â ½ÇÇàÀ» ³¡³»°í ³ª¼ Àç½ÃÀÛÇÒ ¼ö ¾ø½À´Ï´Ù.
IllegalThreadStateException
- thread°¡ À̹Ì
½ÃÀÛÇϰí ÀÖ¾úÀ» °æ¿ìrun()
,
stop()
public void run()
Runnable
½ÇÇà °´Ã¼¸¦ »ç¿ëÇØ ÀÛ¼ºµÇ¾úÀ» °æ¿ì, ±× Runnable
°´Ã¼ÀÇ run
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. ±×·¸Áö ¾ÊÀº °æ¿ì, ÀÌ ¸Þ¼µå´Â ¾Æ¹«°Íµµ ½Ç½ÃÇÏÁö ¾Ê°í º¹±ÍÇÕ´Ï´Ù.
Thread
¼ºê Ŭ·¡½º´Â ÀÌ ¸Þ¼µå¸¦ ¿À¹ö¶óÀ̵å(override) ÇÏÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù.
Runnable
³»ÀÇ run
start()
,
stop()
,
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)
,
Runnable.run()
@Deprecated public final void stop()
ThreadDeath
¿¹¿Ü°¡ ½ºÅþƷ¡¿¡¼ À§¿¡°Ô ÀüÇÒ ¼ö ÀÖ¾ú´ø °á°ú, ±× thread¿¡ ÀÇÇØ ¶ô µÇ°í ÀÖ´ø ¸ð´ÏÅÍÀÇ ¶ôÀÌ ¸ðµÎ ÇØÁ¦µË´Ï´Ù. ÀÌ·¯ÇÑ ¸ð´ÏÅÍ¿¡ ÀÇÇØ Á÷Àü±îÁö º¸È£µÇ°í ÀÖ´ø °´Ã¼°¡ Á¤ÇÕ¼ºÀÇ ¾ø´Â »óÅ¿¡ ÀÖ¾úÀ» °æ¿ì, ¸Á°¡Áø °´Ã¼´Â ´Ù¸¥ thread¿¡ ´ëÇØ¼ °¡½Ã°¡ µÇ¾î, µ¿ÀÛÀÌ º¸ÁõµÇÁö ¾Ê´Â °ÍÀÌ ÀÖ½À´Ï´Ù. ¸¹Àº °æ¿ì, Ÿ°Ù threadÀÇ ½ÇÇà Á¤Áö¸¦ Áö½ÃÇÏ·Á¸é,
stop
´Â ¾Æ´Ï°í, ´ÜÁö ÀϺÎÀÇ º¯¼ö¸¦ º¯°æÇÏ´Â Äڵ带 »ç¿ëÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù. Ÿ°Ù thread´Â ÀÌ º¯¼ö¸¦ Á¤±âÀûÀ¸·Î Ã¼Å©ÇØ, º¯¼ö°¡ ½ÇÇà Á¤Áö¸¦ Áö½ÃÇϰí ÀÖ´Â °æ¿ì´Â run ¸Þ¼µå·ÎºÎÅÍ ÀûÀýÈ÷ º¹±ÍÇÕ´Ï´Ù. Á¶°Ç º¯¼öµîÀ¸·Î Ÿ°Ù thread°¡ ¿À·§µ¿¾È ´ë±âÇϰí ÀÖ´Â °æ¿ì, ´ë±â¸¦ ÁߴܽÃŰ·Á¸é,
interrupt
¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ.
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ ÀνºÅç µÇ°í ÀÖ´Â °æ¿ì, this
¸¦ Àμö·Î¼ ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkAccess
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. ÀÌ °á°ú, ÇöÀçÀÇ thread·Î SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
¶Ç, ÀÌ thread°¡ ÇöÀçÀÇ thread¿Í ´Ù¸¥ °æ¿ì, Áï, ÇöÀçÀÇ thread°¡ ÀڽŠÀÌ¿ÜÀÇ thread¸¦ Á¤ÁöÇÏ·Á°í Çϰí ÀÖ´Â °æ¿ì´Â RuntimePermission("stopThread")
¸¦ Àμö·Î¼ ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission
¸Þ¼µåµµ È£ÃâÇÕ´Ï´Ù. ÀÌ °æ¿ì¿¡µµ, ÇöÀçÀÇ thread·Î SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
ÀÌ thread¿¡ ÀÇÇØ ³ªÅ¸³»Áö´Â thread´Â ±×°ÍÀÌ ½ÇÇàÇϰí ÀÖ´ø µ¿ÀÛ¿¡ °ü°è¾øÀÌ °Á¦ÀûÀ¸·Î ÀÌ»ó Á¤Áö ´çÇØ »õ·Ó°Ô »ý¼ºÇÑ ThreadDeath
°´Ã¼¸¦ ¿¹¿Ü·Î¼ Throw ÇÕ´Ï´Ù.
¾ÆÁ÷ ½ÃÀ۵Ǿî ÀÖÁö ¾ÊÀº thread¸¦ Á¤ÁöÇÒ ¼ö ÀÖ½À´Ï´Ù . thread°¡ ÃÖÁ¾ÀûÀ¸·Î ½ÃÀÛµÇÀÚ, °ð¹Ù·Î Á¾·áÇÕ´Ï´Ù.
¾îÇø®ÄÉÀ̼ÇÀº º¸Åë°ú´Â ´Ù¸¥ Ŭ¸° ¾÷ µ¿ÀÛÀ» ½ÇÇàÇØ¾ß ÇÏ´Â °æ¿ì¸¦ Á¦¿ÜÇØ, ThreadDeath
¸¦ ijġ ÇØ¾ß ÇÏÁö´Â ¾Ê½À´Ï´Ù. ´Ù¸¸, ThreadDeath
¸¦ Throw Çϸé, thread°¡ Á¤½ÄÀ¸·Î Á¾·áÇϱâ Àü¿¡ try
¹®ÀÇ finally
ÀýÀÌ ½ÇÇàµÇ´Â °Í¿¡ ÁÖÀÇÇØ ÁÖ¼¼¿ä. catch
ÀýÀÌ ThreadDeath
°´Ã¼¸¦ ijġ ÇÏ´Â °æ¿ì´Â thread°¡ ½ÇÁ¦·Î Á¾·áÇϵµ·Ï °´Ã¼¸¦ Throw ´Ù½Ã ÇÏ´Â °ÍÀÌ Áß¿äÇÕ´Ï´Ù.
±×·¸Áö ¾ÊÀº °æ¿ì, ijġµÇ¾î ÀÖÁö ¾ÊÀº ¿¹¿Ü¸¦ Ãë±ÞÇÏ´Â ÃÖ°í ·¹º§ÀÇ ¿¡·¯ Çڵ鷯´Â ijġµÇ¾î ÀÖÁö ¾ÊÀº ¿¹¿Ü°¡ ThreadDeath
ÀνºÅϽºÀ̸é, ¸Þ¼¼Áö¸¦ Ãâ·ÂÇϰųª ¾îÇø®ÄÉÀ̼ǿ¡ ÅëÁöÇϰųª ÇÏ´Â °ÍÀº ÇÏÁö ¾Ê½À´Ï´Ù.
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìinterrupt()
,
checkAccess()
,
run()
,
start()
,
ThreadDeath
,
java.lang.Throwable)(java.lang.Thread,
,
SecurityManager.checkAccess(Thread)
,
SecurityManager.checkPermission(java.security.Permission)
@Deprecated public final void stop(Throwable obj)
stop()
¸¦
ÂüÁ¶ÇϽʽÿÀ. °Ô´Ù°¡ ÀÌ ¸Þ¼µå´Â Ÿ°Ù thread·Î ó¸®ÀÇ Áغñ°¡ µÇ¾î ÀÖÁö ¾ÊÀº ¿¹¿ÜÀÇ »ý¼º¿¡ »ç¿ëµÇ´Â ÀÏÀÌ ÀÖ´Â Á¡¿¡¼µµ À§ÇèÇÕ´Ï´Ù (ÀÌ ¸Þ¼µå°¡ ¾øÀ¸¸é thread¿¡ ÀÇÇØ Throw µÉ¸®°¡ ¾ø´Â üũµÈ ¿¹¿Ü µî). ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ.
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ ÀνºÅç µÇ°í ÀÖ´Â °æ¿ì, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkAccess
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. ÀÌ °á°ú, ÇöÀçÀÇ thread·Î SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
¶Ç, ÀÌ thread°¡ ÇöÀçÀÇ thread¿Í ´Ù¸¥ °æ¿ì, Áï, ÇöÀçÀÇ thread°¡ ÀڽŠÀÌ¿ÜÀÇ thread¸¦ Á¤ÁöÇÏ·Á°í Çϰí ÀÖ´Â °æ¿ì, ¶Ç´Â obj
°¡ ThreadDeath
ÀνºÅϽº°¡ ¾Æ´Ñ °æ¿ì´Â RuntimePermission("stopThread")
¸¦ Àμö·Î¼ ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. ÀÌ °æ¿ì¿¡µµ, ÇöÀçÀÇ thread·Î SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
Àμö obj
°¡ nullÀÎ °æ¿ì, ÇöÀçÀÇ thread·Î NullPointerException
°¡ ¹ß»ý µË´Ï´Ù.
ÀÌ thread¿¡ ÀÇÇØ ³ªÅ¸³»Áö´Â thread´Â ±×°ÍÀÌ ½ÇÇàÇÏ´Â µ¿ÀÛ¿¡´Â °ü°è¾øÀÌ °Á¦ÀûÀ¸·Î Á¾·áµÇ¾î ¿¹¿Ü·Î¼ Throwable
°´Ã¼ obj
°¡ ¹ß»ý µË´Ï´Ù. À̰ÍÀº º¸Åë¿¡ ¼´Â ÇàÇØÁöÁö ¾Ê´Â µ¿ÀÛÀ̱⠶§¹®¿¡
ÀϹÝÀûÀ¸·Î Àμö¸¦ ¼³Á¤ÇÏÁö ¾Ê´Â stop
¸Þ¼µå¸¦ »ç¿ëÇØ ÁÖ¼¼¿ä.
¾ÆÁ÷ ½ÃÀ۵Ǿî ÀÖÁö ¾ÊÀº thread¸¦ Á¤ÁöÇÒ ¼ö ÀÖ½À´Ï´Ù . thread°¡ ÃÖÁ¾ÀûÀ¸·Î ½ÃÀÛµÇÀÚ, °ð¹Ù·Î Á¾·áÇÕ´Ï´Ù.
obj
- Throw ´ë»óÀÇ Throwable °´Ã¼
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìinterrupt()
,
checkAccess()
,
run()
,
start()
,
stop()
,
SecurityManager.checkAccess(Thread)
,
SecurityManager.checkPermission(java.security.Permission)
public void interrupt()
ÇöÀçÀÇ thread°¡ Àڽſ¡°Ô ³¢¾îµéÁö ¾ÊÀº ÇÑ (ÀÌ ÀÎÅÍ·´Æ®´Â Çã°¡µÈ´Ù), ÀÌ threadÀÇ checkAccess
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. ÀÌ ¸Þ¼µå¿¡ÀÇÇØ SecurityException
ÀÌ ¹ß»ýµÇ´Â °æ¿ì°¡ ÀÖ½À´Ï´Ù.
Object
Ŭ·¡½ºÀÇ wait()
,
wait(long)
,
¶Ç´Â wait(long, int)
¸Þ¼µåÀÇ È£ÃâÇØ, ¶Ç´Â ÀÌ Å¬·¡½ºÀÇ join()
,
join(long)
,
join(long, int)
,
sleep(long)
,
¶Ç´Â sleep(long, int)
¸Þ¼µåÀÇ È£Ãâ·Î ÀÌ thread°¡ ºí·Ï µÇ´Â °æ¿ì, ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº´Â Ŭ¸®¾î µÇ¾îInterruptedException
¸¦
¹Þ½À´Ï´Ù.
¿¡ ´ëÇÑ I/O Á¶ÀÛÀ¸·Î ÀÌ thread°¡ ºí·Ï µÇ´Â °æ¿ì, ä³ÎÀº ´ÝÇôÁ® threadÀÇ ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº°¡ ¼³Á¤µË´Ï´Ù. ¶Ç, thread´Â interruptible channel
ClosedByInterruptException
¸¦
¹Þ½À´Ï´Ù.
Selector
·Î ÀÌ thread°¡ ºí·Ï µÇ´Â °æ¿ì, threadÀÇ ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº°¡ ¼³Á¤µÇ¾î, ¼±Åà Á¶ÀÛÀ¸·ÎºÎÅÍ Áï¼®¿¡¼ ¸®Åϵ˴ϴÙ
. º¸Åë, ¸®ÅϵÈ
°ªÀº ¼¿·ºÅÍÀÇ wakeup
¸Þ¼µå°¡ ºÒ·Á °¬À» °æ¿ì¿Í °°ÀÌ, Á¦·Î ÀÌ¿ÜÀÇ °ªÀÌ µË´Ï´Ù.
Àü¼úÀÇ Á¶°ÇÀÇ ¾î´À °Í¿¡µµ µé¾î¸ÂÁö ¾Ê´Â °æ¿ì, ÀÌ threadÀÇ ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº°¡ ¼³Á¤µË´Ï´Ù.
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìpublic static boolean interrupted()
true
, ±×·¸Áö ¾ÊÀº °æ¿ì´Â false
isInterrupted()
public boolean isInterrupted()
true
, ±×·¸Áö ¾ÊÀº °æ¿ì´Â false
interrupted()
@Deprecated public void destroy()
suspend()
¿Í
°ÅÀÇ ¶È°°ÀÌ µ¥µå ·ÏÀÌ ¹ß»ýÇÕ´Ï´Ù. Ÿ°Ù thread°¡ Áß¿äÇÑ system resource¸¦ º¸È£ÇÏ´Â ¶ôÀ» º¸°ü À¯ÁöÇÑ »óÅ·ΠÆÄ±âµÇ¾úÀ» °æ¿ì, ¾î´À threadµµ ´Ù½Ã ÀÌ ÀÚ¿ø¿¡ ¾×¼¼½º ÇÒ ¼ö ¾ø½À´Ï´Ù. ´Ù¸¥ thread°¡ ÀÌ ÀÚ¿øÀ» Àá±×·Á°í Çϸé, µ¥µå ·ÏÀÌ ¹ß»ýÇÕ´Ï´Ù. º¸Åë, ±×·¯ÇÑ µ¥µå ·ÏÀº ÀÚ½ÅÀ» ¡¸´Ù¿î ´çÇß´Ù¡¹ÇÁ·Î¼¼½º·Î¼ Ç¥¸íÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ.
NoSuchMethodError
¸¦
Throw ÇÕ´Ï´Ù.
NoSuchMethodError
- »ó½Ãpublic final boolean isAlive()
true
, ±×·¸Áö ¾ÊÀº °æ¿ì´Â false
@Deprecated public final void suspend()
resume
¸¦ È£ÃâÇϱâ Àü¿¡ ÀÌ ¸ð´ÏÅ͸¦ Àá±×·Á°í Çϸé, µ¥µå ·ÏÀÌ ¹ß»ýÇÕ´Ï´Ù. º¸Åë, ±×·¯ÇÑ µ¥µå ·ÏÀº ÀÚ½ÅÀ» ¡¸´Ù¿î ´çÇß´Ù¡¹ÇÁ·Î¼¼½º·Î¼ Ç¥¸íÇÕ´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ.
¿ì¼±, ÀÌ threadÀÇ checkAccess
¸Þ¼µå°¡ Àμö¾øÀÌ È£ÃâÇÕ´Ï´Ù. ÀÌ °á°ú, ÇöÀçÀÇ thread³»¿¡¼ SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
thread´Â »ýÁ¸Çϰí ÀÖ´Â °æ¿ì¿¡ ÁߴܵǾî Àç°³µÇÁö ¾Ê´Â 󸮸¦ ¸ÕÀú ÁøÇàÇÒ ¼ö ¾ø½À´Ï´Ù.
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìcheckAccess()
@Deprecated public final void resume()
suspend()
¿Í
ÇÔ²² »ç¿ëÇϱâ À§ÇØÀÎ ¸¸Å Á¦°øµÇ°í ÀÖ½À´Ï´Ù. ÀÚ¼¼ÇÑ ³»¿ëÀº ¡¸Thread.stop, Thread.suspend ¹× Thread.resume°¡ Ãßõ µÇÁö ¾Ê´Â ÀÌÀ¯¡¹¸¦ ÂüÁ¶ÇϽʽÿÀ.
¿ì¼±, ÀÌ threadÀÇ checkAccess
¸Þ¼µå°¡ Àμö¾øÀÌ È£ÃâÇÕ´Ï´Ù. ÀÌ °á°ú, ÇöÀçÀÇ thread³»¿¡¼ SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
thread´Â »ýÁ¸Çϰí ÀÖÁö¸¸ Áߴܵǰí ÀÖ´Â °æ¿ì, ½ÇÇàÀÌ Àç°³µÇ¾î 󸮸¦ ¸ÕÀú ÁøÇàÇÏ´Â °ÍÀÌ Çã°¡µË´Ï´Ù.
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìcheckAccess()
,
suspend()
public final void setPriority(int newPriority)
¿ì¼±, ÀÌ threadÀÇ checkAccess
¸Þ¼µå°¡ Àμö¾øÀÌ È£ÃâÇÕ´Ï´Ù. ÀÌ °á°ú, SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
±×·¸Áö ¾ÊÀº °æ¿ì, ÀÌ threadÀÇ ¿ì¼± ¼øÀ§´Â ÁöÁ¤µÈ newPriority
¿Í
threadÀÇ thread ±×·ìÀÇ ÃÖ°í Çã¿ë ¿ì¼± ¼øÀ§ ÁßÀÇ ¾î´À ÂÊÀÎÁö ÀÛÀº ÆíÀ¸·Î ¼³Á¤µË´Ï´Ù.
newPriority
- ÀÌ thread¸¦ ¼³Á¤ÇÏ´Â ¿ì¼± ¼øÀ§
IllegalArgumentException
- ¿ì¼± ¼øÀ§°¡ MIN_PRIORITY
~ MAX_PRIORITY
¹üÀ§¿ÜÀÎ °æ¿ì
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìgetPriority()
,
checkAccess()
,
getPriority()
,
getThreadGroup()
,
MAX_PRIORITY
,
MIN_PRIORITY
,
ThreadGroup.getMaxPriority()
public final int getPriority()
setPriority(int)
,
setPriority(int)
public final void setName(String name)
name
¿¡ µ¿ÀÏÇØÁöµµ·Ï º¯°æÇÕ´Ï´Ù.
¿ì¼±, ÀÌ threadÀÇ checkAccess
¸Þ¼µå°¡ Àμö¾øÀÌ È£ÃâÇÕ´Ï´Ù. ÀÌ °á°ú, SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
name
- ÀÌ threadÀÇ »õ·Î¿î À̸§
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìgetName()
,
checkAccess()
,
getName()
public final String getName()
setName(java.lang.String)
,
setName(java.lang.String)
public final ThreadGroup getThreadGroup()
public static int activeCount()
public static int enumerate(Thread [] tarray)
enumerate
¸Þ¼µå¸¦, ¹è¿ Àμö¸¦ ÁöÁ¤ÇØ È£ÃâÇÒ »ÓÀÔ´Ï´Ù.
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â °æ¿ì, enumerate
¸Þ¼µå´Â thread ±×·ìÀ» Àμö·Î¼ ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkAccess
¸Þ¼µå¸¦ È£ÃâÇÕ´Ï´Ù. ÀÌ °á°ú, SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
tarray
- Thread °´Ã¼ÀÇ Ä«ÇÇó ¹è¿
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkAccess
¸Þ¼µå°¡ ÀÌ Á¶ÀÛÀ» Çã°¡ÇÏÁö ¾Ê´Â °æ¿ìThreadGroup.enumerate(java.lang.Thread[])
,
SecurityManager.checkAccess(java.lang.ThreadGroup)
@Deprecated public int countStackFrames()
suspend()
¿¡
ÀÇÁ¸ÇÕ´Ï´Ù. ¶Ç, ÀÌ È£ÃâÀÇ °á°ú´Â º¸ÁõµÇÁö ¾Ê½À´Ï´Ù.
IllegalThreadStateException
- ÀÌ thread°¡ ÁߴܵÇÁö ¾Ê´Â °æ¿ìpublic final void join(long millis) throws InterruptedException
millis
¹Ð¸® ¼¼ÄÁµå ´ë±âÇÕ´Ï´Ù. 0
ŸÀÓ ¾Æ¿ôÀº ¿µ¿øÈ÷ ´ë±âÇÏ´Â °ÍÀ»ÀǹÌÇÕ´Ï´Ù.
millis
- ¹Ð¸® ¼¼ÄÁµå ´ÜÀ§ÀÇ ´ë±â ½Ã°£
InterruptedException
- º°ÀÇ thread°¡ ÇöÀçÀÇ thread¿¡ ³¢¾îµé¾úÀ» °æ¿ì. ÀÌ ¿¹¿Ü°¡ Throw µÇ¸é, ÇöÀçÀÇ threadÀÇ ¡¸ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº¡¹´Â Ŭ¸®¾î µÈ´Ùpublic final void join(long millis, int nanos) throws InterruptedException
millis
¹Ð¸® ¼¼ÄÁµå¿¡ nanos
³ª³ëÃʸ¦ °¡»êÇÑ »çÀÌ, ÀÌ thread°¡ Á¾·áÇÏ´Â °ÍÀ» ´ë±âÇÕ´Ï´Ù.
millis
- ¹Ð¸® ¼¼ÄÁµå ´ÜÀ§ÀÇ ´ë±â ½Ã°£nanos
- ´ë±âÇϱâ À§ÇÑ 0 ~ 999999
Ãß°¡ ³ª³ëÃÊ
IllegalArgumentException
- millis
°ªÀÌ À½¼öÀÇ °æ¿ì, ¶Ç´Â nanos
°ªÀÌ 0 ~ 999999
¹üÀ§¿ÜÀÇ °æ¿ì
InterruptedException
- º°ÀÇ thread°¡ ÇöÀçÀÇ thread¿¡ ³¢¾îµé¾úÀ» °æ¿ì. ÀÌ ¿¹¿Ü°¡ Throw µÇ¸é, ÇöÀçÀÇ threadÀÇ ¡¸ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº¡¹´Â Ŭ¸®¾î µÈ´Ùpublic final void join() throws InterruptedException
InterruptedException
- º°ÀÇ thread°¡ ÇöÀçÀÇ thread¿¡ ³¢¾îµé¾úÀ» °æ¿ì. ÀÌ ¿¹¿Ü°¡ Throw µÇ¸é, ÇöÀçÀÇ threadÀÇ ¡¸ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº¡¹´Â Ŭ¸®¾î µÈ´Ùpublic static void dumpStack()
Throwable.printStackTrace()
public final void setDaemon(boolean on)
ÀÌ ¸Þ¼µå´Â thread ½ÃÀÛÀü¿¡ È£ÃâÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù.
ÀÌ ¸Þ¼µå´Â Àμö¾øÀÌ ÀÌ threadÀÇ checkAccess
¸Þ¼µå¸¦ È£ÃâÇÕ´Ï´Ù. ÀÌ °á°ú, ÇöÀçÀÇ thread·Î SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
on
- true
ÀÎ °æ¿ì, ÀÌ thread¸¦ demon thread·Î¼ ¸¶Å© ÇÑ´Ù
IllegalThreadStateException
- ÀÌ thread°¡ Ȱ¼ºÈµÈ °æ¿ì
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¸¦ º¯°æÇÒ ¼ö ¾ø´Â °æ¿ìisDaemon()
,
checkAccess()
public final boolean isDaemon()
true
, ±×·¸Áö ¾ÊÀº °æ¿ì´Â false
setDaemon(boolean)
public final void checkAccess()
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â °æ¿ì, ÀÌ thread°¡ ±× Àμö·Î ÁöÁ¤µÇ¾î checkAccess
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù. ÀÌ °á°ú, SecurityException
°¡ ¹ß»ýµÇ´Â ÀÏÀÌ ÀÖ½À´Ï´Ù.
ÁÖ: ÀÌ ¸Þ¼µå°¡ JDK 1.1 ¿¡¼´Â final°¡ ¾Æ´Ï¾ú´ø °ÍÀº À߸øÀÔ´Ï´Ù. Java 2 Ç÷§Æû¿¡¼´Â final°¡ µÇ¾î ÀÖ½À´Ï´Ù.
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ thread¿¡ÀÇ ¾×¼¼½º°¡ ¿ë¼µÇÁö ¾ÊÀº °æ¿ìSecurityManager.checkAccess(java.lang.Thread)
public String toString()
Object
³»ÀÇ toString
public ClassLoader getContextClassLoader()
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â °æ¿ì, È£ÃâÃøÀÇ Å¬·¡½º ·Î´õ°¡ nullÀº ¾Æ´Ï°í, ÄÁÅØ½ºÆ®
Ŭ·¡½º ·Î´õ°¡ ¿ä±¸µÇ°í ÀÖ´Â threadÀÇ ÄÁÅØ½ºÆ®
Ŭ·¡½º ·Î´õ¿Í °°Áö ¾Ê°í, ±× ÄÁÅØ½ºÆ®
Ŭ·¡½º ·Î´õÀÇ »óÀ§ °´Ã¼µµ ¾Æ´Ò ¶§´Â ÄÁÅØ½ºÆ®
ClassLoader¸¦ ÃëµæÇØµµ ±¦ÂúÀºÁö ¾î¶²Áö¸¦ È®ÀÎÇϱâ À§Çؼ
RuntimePermission("getClassLoader")
Á¢±Ù ±ÇÇÑÀ» »ç¿ëÇØ, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù.
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission
¸Þ¼µå°¡ ÄÁÅØ½ºÆ®
ClassLoader
ÃëµæÀ» Çã°¡ÇÏÁö ¾Ê´Â °æ¿ìsetContextClassLoader(java.lang.ClassLoader)
,
SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public void setContextClassLoader(ClassLoader cl)
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇÏ´Â °æ¿ì, ÃÖÃÊ·Î ÄÁÅØ½ºÆ®
ClassLoader¸¦ ¼³Á¤Çصµ ÁÁÀºÁö ¾î¶²Áö¸¦ Á¶»çÇϱâ À§Çؼ RuntimePermission("setContextClassLoader")
Á¢±Ù ±ÇÇÑÀ» »ç¿ëÇØ checkPermission
¸Þ¼µå°¡ È£ÃâµË´Ï´Ù.
cl
- ÀÌ Thread
ÄÁÅØ½ºÆ®
ClassLoader
SecurityException
- ÇöÀçÀÇ thread°¡ ÄÁÅØ½ºÆ®
ClassLoader¸¦ ¼³Á¤ÇÒ ¼ö ¾ø´Â °æ¿ìgetContextClassLoader()
,
SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
public static boolean holdsLock(Object obj)
ÀÌ ¸Þ¼µå´Â ¾Æ·¡¿Í °°ÀÌ, ÇÁ·Î±×·¥ÀÌ, ÇöÇà thread°¡ ÁöÁ¤µÈ ¶ôÀ» ÀÌ¹Ì º¸°ü À¯ÁöÇϰí ÀÖ´Â °ÍÀ» ³ªÅ¸³¾ ¶§¿¡ »ç¿ëµË´Ï´Ù.
assert Thread.holdsLock(obj);
obj
- ¼ÒÀ¯±ÇÀÇ ¶ôÀ» Å×½ºÆ®ÇÏ´Â °´Ã¼
NullPointerException
- obj°¡ nullÀÎ °æ¿ìpublic StackTraceElement [] getStackTrace()
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, ÀÌ thread°¡ ÇöÀçÀÇ thread°¡ ¾Æ´Ñ °æ¿ì, ½ºÅà Ʈ·¹À̽º¸¦ ÃëµæÇØµµ ÁÁÀºÁö ¾î¶²Áö¸¦ Á¶»çÇϱâ À§Çؼ RuntimePermission("getStackTrace") Á¢±Ù ±ÇÇÑÀ» »ç¿ëÇØ ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission ¸Þ¼µå°¡ È£ÃâµË´Ï´Ù.
°¡»ó ¸Ó½Å¾È¿¡´Â ƯÁ¤ÀÇ »óȲÇÏ·Î ½ºÅà Ʈ·¹À̽º·ÎºÎÅÍ 1°³ ÀÌ»óÀÇ ½ºÅà ÇÁ·¹ÀÓÀ» »ý·« ÇÏ´Â °ÍÀÌ ÀÖ½À´Ï´Ù. ±Ø´ÜÀûÀÎ °æ¿ì, ÀÌ thread¿¡ °üÇÑ ½ºÅà Ʈ·¹À̽º Á¤º¸¸¦ °¡ÁöÁö ¾Ê´Â °¡»ó ¸Ó½ÅÀÌ, ÀÌ ¸Þ¼µå·ÎºÎÅÍ ±æÀÌ Á¦·ÎÀÇ ¹è¿À» µ¹·ÁÁÖ´Â °ÍÀÌ Çã°¡µË´Ï´Ù.
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission ¸Þ¼µå°¡ threadÀÇ ½ºÅà Ʈ·¹À̽ºÀÇ ÃëµæÀ» Çã°¡ÇÏÁö ¾Ê´Â °æ¿ìSecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
,
Throwable.getStackTrace()
public static Map <Thread, StackTraceElement []> getAllStackTraces()
getStackTrace
¸Þ¼µå¿¡ ´ëÇØ¼ ÁöÁ¤µÈ Æ÷¸ËÀÔ´Ï´Ù.
ÀÌ ¸Þ¼µå°¡ ºÒ·Á°¡ °í ÀÖ´Â µ¿¾È¿¡ thread°¡ ½ÇÇàµÇ°í ÀÖÀ» °¡´É¼ºÀÌ ÀÖ½À´Ï´Ù. °¢ threadÀÇ ½ºÅà Ʈ·¹À̽º´Â snapshot¸¦ ³ªÅ¸³¾ »ÓÀÔ´Ï´Ù. °¢ ½ºÅà Ʈ·¹À̽º´Â ´Ù¸¥ ½Ã±â¿¡ ÃëµæÇÒ ¼ö ÀÖ½À´Ï´Ù. °¡»ó ¸Ó½ÅÀÌ thread¿¡ °üÇÑ ½ºÅà Ʈ·¹À̽º Á¤º¸¸¦ °¡ÁöÁö ¾Ê´Â °æ¿ì, ¸ÊÄ¡¿¡ ±æÀÌ Á¦·ÎÀÇ ¹è¿ÀÌ ¸®Åϵ˴ϴ٠.
½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, ÀÌ thread°¡ ÇöÀçÀÇ thread°¡ ¾Æ´Ñ °æ¿ì, ¸ðµç threadÀÇ ½ºÅà Ʈ·¹À̽º¸¦ ÃëµæÇØµµ ÁÁÀºÁö ¾î¶²Áö¸¦ Á¶»çÇϱâ À§Çؼ RuntimePermission("getStackTrace") Á¢±Ù ±ÇÇѰú RuntimePermission("modifyThreadGroup") Á¢±Ù ±ÇÇÑÀ» »ç¿ëÇØ ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission ¸Þ¼µå°¡ È£ÃâµË´Ï´Ù.
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀúÀÇ checkPermission ¸Þ¼µå°¡ threadÀÇ ½ºÅà Ʈ·¹À̽ºÀÇ ÃëµæÀ» Çã°¡ÇÏÁö ¾Ê´Â °æ¿ìgetStackTrace()
,
SecurityManager.checkPermission(java.security.Permission)
,
RuntimePermission
,
Throwable.getStackTrace()
public long getId()
public Thread.State getState()
public static void setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)
ijġ µÇÁö ¾Ê´Â ¿¹¿ÜÀÇ Ãë±ÞÀº thread¿¡ ÀÇÇØ ¿ì¼± Á¦¾îµÇ¾î ´ÙÀ½¿¡ thread ThreadGroup
°´Ã¼¿¡ÀÇÇØ ÃÖÁ¾ÀûÀ¸·Î´Â µðÆúÆ®ÀÇ Ä³Ä¡ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯¿¡ ÀÇÇØ Á¦¾îµË´Ï´Ù. thread°¡ ¸í½ÃÀûÀΠijġ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯 ¼¼Æ®¸¦ °¡ÁöÁö ¾Ê´Â °æ¿ì, threadÀÇ thread ±×·ì (Ä£thread ±×·ìÀ» Æ÷ÇÔÇÑ´Ù)Àº, uncaughtException ¸Þ¼µå¸¦ Ư¼öÈ ÇÏÁö ¾Ê½À´Ï´Ù. ´ÙÀ½¿¡
µðÆúÆ® Çڵ鷯ÀÇ uncaughtException ¸Þ¼µå°¡ È£ÃâµË´Ï´Ù.
µðÆúÆ®ÀÇ Ä³Ä¡ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯¸¦ ¼³Á¤ÇÏ´Â °ÍÀ¸·Î ¾îÇø®ÄÉÀ̼ǿ¡¼´Â ½Ã½ºÅÛÀ¸·Î Á¦°øµÈ ¡¸µðÆúÆ®¡¹ÀÇ µ¿ÀÛÀ» ÀÌ¹Ì ¹Þ¾ÆµéÀ̰í ÀÖ´Â threadÀÇ Ä³Ä¡ µÇÁö ¾Ê´Â ¿¹¿Ü¸¦ Ãë±ÞÇÏ´Â ¹æ¹ý (ƯÁ¤ÀÇ µð¹ÙÀ̽º³ª ÆÄÀÏ¿¡ÀÇ ·Î±×Àεî)À» º¯°æÇÒ ¼ö ÀÖ½À´Ï´Ù.¡¡
º¸Åë, µðÆúÆ®ÀÇ Ä³Ä¡ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯´Â threadÀÇ ThreadGroup °´Ã¼¿Í ´Þ¶ó¼´Â ¾ÈµË´Ï´Ù. À̰ÍÀº ¹«ÇÑÀÇ Àç±Í¸¦ ºÎ¸¦ °¡´É¼ºÀÌ Àֱ⠶§¹®ÀÔ´Ï´Ù.
eh
- µðÆúÆ®ÀÇ Ä³Ä¡ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯·Î¼ »ç¿ëÇÏ´Â °´Ã¼. nullÀÎ °æ¿ì, µðÆúÆ®ÀÇ Çڵ鷯´Â ¾ø´Ù
SecurityException
- ½ÃÅ¥·¯Æ¼ ¸Å´ÏÀú°¡ Á¸ÀçÇØ, RuntimePermission
("setDefaultUncaughtExceptionHandler")¸¦ °ÅºÎÇßÀ» °æ¿ìsetUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
,
getUncaughtExceptionHandler()
,
ThreadGroup.uncaughtException(java.lang.Thread, java.lang.Throwable)
public static Thread.UncaughtExceptionHandler getDefaultUncaughtExceptionHandler()
setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)
ijġ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯¸¦ ¸í½ÃÀûÀ¸·Î ¼³Á¤ÇÏ´Â °ÍÀ¸·Î thread´Â ijġ µÇÁö ¾Ê´Â ¿¹¿Ü¸¦ ¿ÏÀüÇÏ°Ô Á¦¾îÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ·¯ÇÑ Çڵ鷯°¡ ¼³Á¤µÇ¾î ÀÖÁö ¾ÊÀº °æ¿ì´Â threadÀÇ ThreadGroup °´Ã¼°¡ Çڵ鷯·Î¼ ±â´ÉÇÕ´Ï´Ù.
eh
- threadÀÇ Ä³Ä¡ µÇÁö ¾Ê´Â ¿¹¿Ü Çڵ鷯·Î¼ »ç¿ëµÇ´Â °´Ã¼. nullÀÎ °æ¿ì, thread´Â ¸í½ÃÀûÀÎ Çڵ鷯¸¦ °¡ÁöÁö ¾Ê´Â´Ù
SecurityException
- ÇöÀçÀÇ thread°¡ ÀÌ threadÀÇ º¯°æÀÌ ¿ë¼µÇÁö ¾ÊÀº °æ¿ìsetDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)
,
ThreadGroup.uncaughtException(java.lang.Thread, java.lang.Throwable)
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º Â÷ÀÇ Å¬·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: NESTED | Çʵå | constructor | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy µµ ÂüÁ¶ÇϽʽÿÀ.