|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º ´ÙÀ½ Ŭ·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: NESTED | Çʵå | constructor | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
java.lang.Objectjava.util.concurrent.locks.ReentrantReadWriteLock.ReadLock
public static class ReentrantReadWriteLock.ReadLock
ReentrantReadWriteLock.readLock()
¸Þ¼µå¿¡ ÀÇÇØ ¸®ÅϵÈ
¶ô
»ý¼ºÀÚ °³¿ä | |
---|---|
protected |
ReentrantReadWriteLock.ReadLock (ReentrantReadWriteLock lock)
¼ºê Ŭ·¡½º¿¡ ÀÇÇØ »ç¿ëµÇ´Â »ý¼ºÀÚ ÀÔ´Ï´Ù. |
¸Þ¼µå °³¿ä | |
---|---|
void |
lock ()
read ¶ôÀ» ÃëµæÇÕ´Ï´Ù. |
void |
lockInterruptibly ()
ÇöÀçÀÇ thread°¡ interrupted °¡ ¾Æ´Ñ °æ¿ì, read ¶ôÀ» ÃëµæÇÕ´Ï´Ù. |
Condition |
newCondition ()
ReadLocks°¡ »óŸ¦ Áö¿ø ÇÏÁö ¾Ê±â ¶§¹®¿¡ UnsupportedOperationExceptionÀ» Throw ÇÕ´Ï´Ù. |
String |
toString ()
ÀÌ ¶ô ¹× ±× »óŸ¦ ½Äº°Çϴ ij¸¯ÅÍ ¶óÀÎÀ» ¸®ÅÏÇÕ´Ï´Ù. |
boolean |
tryLock ()
È£Ãâ½Ã¿¡ ´Ù¸¥ thread¿¡ ÀÇÇØ Ãâ·Â ¶ôÀÌ º¸°ü À¯ÁöµÇ¾î ÀÖÁö ¾ÊÀº °æ¿ì¿¡°Ô¸¸, read ¶ôÀ» ÃëµæÇÕ´Ï´Ù. |
boolean |
tryLock (long timeout,
TimeUnit unit)
ÁöÁ¤µÈ ´ë±â ½Ã°£³»¿¡ ´Ù¸¥ thread°¡ Ãâ·Â¶ôÀ» º¸°ü À¯ÁöÇÏÁö ¾Ê°í, ÇöÀçÀÇ thread·Î ÀÎÅÍ·´Æ® °¡ ¹ß»ýÇϰí ÀÖÁö ¾Ê´Â °æ¿ì¿¡
read ¶ôÀ» ÃëµæÇÕ´Ï´Ù. |
void |
unlock ()
ÀÌ ¶ôÀÇ ÇØ¹æÀ» ½ÃµµÇÕ´Ï´Ù. |
Ŭ·¡½º java.lang. Object ·ÎºÎÅÍ »ó¼ÓµÈ ¸Þ¼µå |
---|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
»ý¼ºÀÚ »ó¼¼ |
---|
protected ReentrantReadWriteLock.ReadLock(ReentrantReadWriteLock lock)
lock
- ¿ÜºÎÀÇ ¶ô °´Ã¼
NullPointerException
- ¶ôÀÌ nullÀÎ °æ¿ì¸Þ¼µåÀÇ »ó¼¼ |
---|
public void lock()
Ãâ·Â ¶ôÀÌ ´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ¾î ÀÖÁö ¾ÊÀº °æ¿ì´Â read ¶ôÀ» ÃëµæÇØ Áï½Ã º¹±ÍÇÕ´Ï´Ù.
Ãâ·Â ¶ôÀÌ ´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ°í ÀÖ´Â °æ¿ì, ÇöÀçÀÇ thread´Â threadÀÇ ½ºÄÉÁÙ¸µ¿¡ °üÇØ¼ ¹«È¿°¡ µÇ¾î, read ¶ôÀÌ ÃëµæµÉ ¶§±îÁö ´ë±âÇÕ´Ï´Ù.
Lock
³»ÀÇ lock
public void lockInterruptibly() throws InterruptedException
interrupted
°¡ ¾Æ´Ñ °æ¿ì, read ¶ôÀ» ÃëµæÇÕ´Ï´Ù.
Ãâ·Â ¶ôÀÌ ´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ¾î ÀÖÁö ¾ÊÀº °æ¿ì´Â read ¶ôÀ» ÃëµæÇØ Áï½Ã º¹±ÍÇÕ´Ï´Ù.
Ãâ·Â ¶ôÀÌ ´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ°í ÀÖ´Â °æ¿ì, ÇöÀçÀÇ thread´Â threadÀÇ ½ºÄÉÁÙ¸µ¿¡ °üÇØ¼ ¹«È¿°¡ µÇ¾î, ´ÙÀ½ÀÇ 2°³ Áß ÇÑÂÊÀÌ ÀϾ ¶§±îÁö ´ë±âÇÕ´Ï´Ù.
ÀÎÅÍ·´Æ®
¸¦ ½Ç½ÃÇÑ´Ù
ÇöÀçÀÇ thread·Î
ÀÎÅÍ·´Æ®
°¡ ¹ß»ýÇßÀ» °æ¿ì,
InterruptedException
ÀÌ Throw µÇ¾î ÇöÀçÀÇ threadÀÇ ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº°¡ Ŭ¸®¾î µË´Ï´Ù.
ÀÌ ¸Þ¼µå´Â ¸í½ÃÀûÀÎ ³¢¾îµé¾î Æ÷ÀÎÆ®À̱⠶§¹®¿¡ ÀÌ ±¸Çö¿¡¼´Â º¸Åë ¶Ç´Â ÀçÀÔ °¡´ÉÇÑ ¶ô Ãëµæ¿¡ÀÇ ÀÎÅÍ·´Æ®¿¡ÀÇ ÀÀ´ä¿¡ ³ôÀº ¿ì¼±µµ°¡ ÁÖ¾îÁý´Ï´Ù.
Lock
³»ÀÇ lockInterruptibly
InterruptedException
- ÇöÀçÀÇ thread·Î ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ìThread.interrupt()
public boolean tryLock()
´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ¾î ÀÖÁö ¾ÊÀº °æ¿ì¿¡ Àбâ
¶ôÀ» ÃëµæÇØ, °ª true·Î
Áï½Ã º¹±ÍÇÕ´Ï´Ù. ÀÌ ¶ôÀÌ ±Õµî ¼ø¼ºÎ Á¤Ã¥¸¦ »ç¿ëÇϵµ·Ï ¼³Á¤µÇ¾î ÀÖ´Â °æ¿ì¿¡¼µµ, read ¶ôÀÌ »ç¿ë °¡´ÉÇϸé, ´Ù¸¥ thread°¡ ÇöÀç read ¶ôÀ» ´ë±âÇϰí ÀÖÀ»Áö ¾î¶³Áö¿¡ °ü°è¾øÀÌ, tryLock()
È£Ãâ·Î °ð¹Ù·Î Àбâ
¶ôÀÌ ÃëµæµË´Ï´Ù. ÀÌ ¡¸È¹° ¿î¹Ý¼±¡¹µ¿ÀÛ¿¡ ÀÇÇØ ±Õµî¼ºÀÌ ¾ø¾îÁø´Ù°í´Â ¸»ÇÒ ¼ö ÀÖ¾î À̰ÍÀº ƯÁ¤ÀÇ »óȲÇÏ·Î À¯¿ëÇÕ´Ï´Ù. ÀÌ ¶ôÀÇ ±Õµî ¼³Á¤À» Á¸ÁßÇÏ´Â °æ¿ì´Â °ÅÀÇ µî°¡ÀÎ tryLock(0, TimeUnit.SECONDS)
¸¦
»ç¿ëÇÕ´Ï´Ù (À̰͵µ ÀÎÅÍ·´Æ®¸¦ °ËÃâÇÑ´Ù).
Ãâ·Â ¶ôÀÌ ´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ°í ÀÖ´Â °æ¿ì, ÀÌ ¸Þ¼µå´Â °ª false·Î Áï½Ã º¹±ÍÇÕ´Ï´Ù.
Lock
³»ÀÇ tryLock
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException
ÀÎÅÍ·´Æ®
°¡ ¹ß»ýÇϰí ÀÖÁö ¾Ê´Â °æ¿ì¿¡
read ¶ôÀ» ÃëµæÇÕ´Ï´Ù.
´Ù¸¥ thread°¡ Ãâ·Â¶ôÀ» º¸°ü À¯ÁöÇϰí ÀÖÁö ¾Ê´Â °æ¿ì¿¡ Àбâ
¶ôÀ» ÃëµæÇØ, °ª true·Î
Áï½Ã º¹±ÍÇÕ´Ï´Ù. ÀÌ ¶ôÀÌ ±Õµî ¼ø¼ºÎ Á¤Ã¥¸¦ »ç¿ëÇϵµ·Ï ¼³Á¤µÇ¾î À־, ´Ù¸¥ thread°¡ ¶ôÀ» ´ë±âÇϰí ÀÖ´Â °æ¿ì´Â »ç¿ë °¡´ÉÇÑ ¶ôÀº ÃëµæµÇÁö ¾Ê½À´Ï´Ù. À̰ÍÀº, tryLock()
¸Þ¼µå¿Í´Â ´ëÁ¶ÀûÀÔ´Ï´Ù. ±Õµî ¶ô¿¡ ´ëÇÑ È¹° ¿î¹Ý¼±À» Çã°¡ÇÏÁö ¾Ê´Â ½Ã°£ ¼³Á¤µÈ tryLock¸¦ »ç¿ëÇÏ´Â °æ¿ì´Â ½Ã°£ ¼³Á¤°ú ºñ½Ã°£ ¼³Á¤ÀÇ ¾çÇü½ÄÀ» Á¶ÇÕÇØ »ç¿ëÇÕ´Ï´Ù.
if (lock.tryLock() || lock.tryLock(timeout, unit) ) { ... }
Ãâ·Â ¶ôÀÌ ´Ù¸¥ thread¿¡ ÀÇÇØ º¸°ü À¯ÁöµÇ°í ÀÖ´Â °æ¿ì, ÇöÀçÀÇ thread´Â threadÀÇ ½ºÄÉÁÙ¸µ¿¡ °üÇØ¼ ¹«È¿°¡ µÇ¾î, ´ÙÀ½ÀÇ 3 °³Áß ÇÑÂÊÀÌ ÀϾ ¶§±îÁö ´ë±âÇÕ´Ï´Ù.
ÀÎÅÍ·´Æ®
¸¦ ½Ç½ÃÇÑ´Ù
read ¶ôÀÌ ÃëµæµÇ¸é, true°¡ ¸®Åϵ˴ϴ٠.
ÇöÀçÀÇ thread·Î
ÀÎÅÍ·´Æ®
°¡ ¹ß»ýÇßÀ» °æ¿ì,
InterruptedException
ÀÌ Throw µÇ¾î ÇöÀçÀÇ threadÀÇ ÀÎÅÍ·´Æ® ½ºÅ×ÀÌÅͽº°¡ Ŭ¸®¾î µË´Ï´Ù.
ÁöÁ¤µÈ ´ë±â ½Ã°£ÀÌ °æ°úÇϸé, °ª false°¡ ¸®Åϵ˴ϴ٠. ½Ã°£ÀÌ Á¦·Î ¶Ç´Â ±×°Íº¸´Ù ÀÛÀº °æ¿ì, ¸Þ¼µå´Â ´ë±âÇÏÁö ¾Ê½À´Ï´Ù.
ÀÌ ¸Þ¼µå´Â ¸í½ÃÀûÀÎ ³¢¾îµé¾î Æ÷ÀÎÆ®À̱⠶§¹®¿¡ ÀÌ ±¸Çö¿¡¼´Â º¸Åë ¶Ç´Â ÀçÀÔ °¡´ÉÇÑ ¶ô Ãëµæ ¹× ´ë±â ½Ã°£ °æ°ú ¸®Æ÷Æ®¿¡ÀÇ ÀÎÅÍ·´Æ®¿¡ ´ëÇÑ ÀÀ´ä¿¡ ³ôÀº ¿ì¼±µµ°¡ ÁÖ¾îÁý´Ï´Ù.
Lock
³»ÀÇ tryLock
timeout
- read ¶ôÀ» ´ë±âÇÏ´Â ½Ã°£unit
- timeout ÀμöÀÇ ½Ã°£ ´ÜÀ§
InterruptedException
- ÇöÀçÀÇ thread·Î ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇßÀ» °æ¿ì
NullPointerException
- ´ÜÀ§°¡ nullÀÎ °æ¿ìThread.interrupt()
public void unlock()
¸®´õÀÇ ¼ö°¡ Á¦·Î°¡ µÇ¾úÀ» °æ¿ì, Ãâ·Â ¶ô ½ÃÇàÀ¸·ÎºÎÅÍ ¶ôÀÌ ÀÌ¿ë °¡´ÉÇÏ°Ô µË´Ï´Ù.
Lock
³»ÀÇ unlock
public Condition newCondition()
Lock
³»ÀÇ newCondition
Condition
UnsupportedOperationException
- »ó½Ãpublic String toString()
Object
³»ÀÇ toString
|
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 µµ ÂüÁ¶ÇϽʽÿÀ.