Actually, lots of ways:

  1. No need for synchronization at all if you don't have mutable state.
  2. 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.
  3. You can also use built-in synchronizers. java.util.concurrent.locks.ReentrantLock has the same functionality as the lock you access when using synchronized blocks and methods, and it is even more powerful.

相关文章:

  • 2021-04-28
猜你喜欢
  • 2022-03-04
  • 2022-01-14
  • 2021-06-16
  • 2021-08-23
相关资源
相似解决方案