We can use AtomicInteger to avoid count++ issue in mutli-threading environment.
AtomicInteger provides incrementAndGet() and decrementAndGet() methods which are thread safe.
With use of AtomicInteger, we can solve this problem without using synchronized keyword
more: https://docs.oracle.com/javase/tutorial/essential/concurrency/atomicvars.html
http://javarevisited.blogspot.in/2012/01/how-to-write-thread-safe-code-in-java.html
AtomicInteger provides incrementAndGet() and decrementAndGet() methods which are thread safe.
With use of AtomicInteger, we can solve this problem without using synchronized keyword
more: https://docs.oracle.com/javase/tutorial/essential/concurrency/atomicvars.html
http://javarevisited.blogspot.in/2012/01/how-to-write-thread-safe-code-in-java.html
No comments:
Post a Comment