Quantcast
Channel: Is there a viable use case where Java synchronized keyword is better than Atomics? - Stack Overflow
Browsing all 6 articles
Browse latest View live

Answer by ZhongYu for Is there a viable use case where Java synchronized...

Conceptually, a critical section protected by a lock transform state from one valid state to another.int x, y; // invariant: x==yvoid inc() synchronized(lock) x++; y++;void dec() ...We could...

View Article


Answer by Stephen C for Is there a viable use case where Java synchronized...

Now I wonder why anyone would use synchronized since it is so much slower...Maybe because speed isn't everything.In fact, if you looked objectively at the overall performance benefit of using your...

View Article


Answer by mysterymath for Is there a viable use case where Java synchronized...

From what I understand, the synchronized keyword is actually a moderately heavyweight recursive (re-entrant) lock. For instance, the following (horrible) code would not deadlock:public static Object...

View Article

Answer by Brad Peabody for Is there a viable use case where Java synchronized...

Depends on what you are doing - if you only need the functionality that an atomic provides you, then yes, there would be no need to do the same work yourself (using the synchronized keyword). However,...

View Article

Answer by jtahlborn for Is there a viable use case where Java synchronized...

Because you can't do multiple actions exclusively using only atomics (well, technically you can, because you can implement a "lock" using atomics, but i think that's beside the point). you also can't...

View Article


Is there a viable use case where Java synchronized keyword is better than...

I've not much experience with threading, but I wrote a nifty non-blocking sequential Id generator with Atomics.... It got me a very significant performance boost in testing. Now I wonder why anyone...

View Article
Browsing all 6 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>