ã§ã¯ãReadWriteLockã®ãµã³ãã«ã
èªã¿è¾¼ã¿ã¹ã¬ããã¯äºãã«ããã¯ãããæ¸ãè¾¼ã¿ã¹ã¬ããã¯ä»ã®ã¹ã¬ããã¨ã¯åæã«åãããªããã¨ããããã¯ã§ãã
ãµã³ãã«ã§ã¯ãããé»è»ããæ¸ãè¾¼ã¿ã¹ã¬ããããé»è»ããèªã¿è¾¼ã¿ã¹ã¬ããã§ããããé»è»ããåãã¨ãã«ã¯ä»ã®ã¹ã¬ããã¯åãã¾ããã
ReadWriteLockã®å®è£ ã¨ãã¦ã¯ãåå ¥å¯è½ãªReentrantReadWriteLockãç¨æããã¦ããã®ã§ãããã使ãã¾ãã
ReadWriteLock lock = new ReentrantReadWriteLock();
å®éã«ããã¯ããã¨ãã¯ãReadWriteLockãªãã¸ã§ã¯ãããwriteLock/readLockã¡ã½ããã§æ¸ãè¾¼ã¿ç¨ããã¯ãèªã¿è¾¼ã¿ç¨ããã¯ãåå¾ãã¾ãã
Lock reallock = writer ? lock.writeLock() : lock.readLock();
ãããã£ã¦åå¾ããããã¯ããé常ã®Lockãªãã¸ã§ã¯ãã¨åæ§ã«lock/unlockãã¾ãã
reallock.lock(); reallock.unlock();
ã¨ãããã¨ã§ãã½ã¼ã¹