What are the possible ways to make code thread-safe without using the synchronized
keyword?
Actually, lots of ways:
java.lang.ThreadLocal
.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.Only have variables/references local to methods. Or ensure that any instance variables are immutable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With