Create a method synchronized without using synchronized keyword
Actually, lots of ways:
- No need for synchronization at all if you don't have mutable state.
- No need for synchronization if the mutable state is confined to a single thread. This can be done by using local variables or
java.lang.ThreadLocal. - You can also use built-in synchronizers.
java.util.concurrent.locks.ReentrantLockhas the same functionality as the lock you access when usingsynchronizedblocks and methods, and it is even more powerful.
posted on 2013-11-19 05:23 Step-BY-Step 阅读(154) 评论(0) 收藏 举报
浙公网安备 33010602011771号