3 ms·
I started Java over a decade ago and by then no one was writing synchronized blocks when doing multithreaded code.
by charcircuit 3y ago
I started Java over a decade ago and by then no one was writing synchronized blocks when doing multithreaded code.
- jiggawatts 3y agoYou’re being downvoted, but I haven’t done Java programming in over twenty years and even I knew that!
- CHY872 3y agoI've been coding in Java for a bit longer than that, and in my memory it's always been known that ReentrantLock is _faster_, but synchronized has better language level support (as in, the language won't let you forget to unlock, whereas with locks you need to remember your finally statement). And then, unlike ReentrantLock, synchronized uses no extra memory, which is good for things that end up being uncontended, and then in both cases, the performance doesn't matter if the lock is uncontended, which most of mine were. There of course are things like ErrorProne that statically check that you unlocked your lock, but there's still bugs possible.
- tadfisher 3y agoI hope anyone who learned the horrible construction of double-checked locking would have used an alternative.