4 ms·
I'd actually like to add "Don't touch synchronized functions" to the list. If need be try and use Thread Locals instead.
by gravypod 9y ago
I'd actually like to add "Don't touch synchronized functions" to the list. If need be try and use Thread Locals instead.
- imhoguy 9y agoForemost one should look what java.util.concurrent[0] has to offer before reinventing concurrency patterns from scratch. [0] https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/package-summary.html https://docs.oracle.com/javase/9/docs/api/java/util/concurre...
- aardvark179 9y agoI’ve seen statements like this before, and they are often based on misunderstandings of what either monitors (synchronisation) or ThreadLocal give you. Could you maybe expand your comment to describe what problem with synchronised you would suggest fixing using ThreadLocal?
- sorokod 9y agoDon't think ThreadLocals help when you actually need to share state between threads.
- dboreham 9y agoPlease avoid TLS at all costs unless you really know what you are doing and why. It can blow up GC due to the reference graph becoming highly interconnected via the TLS arrays. This can happen without you being aware because dependent libraries are busy being oh so clever with TLS.
- lamansion 9y agoI don't think this is good advice. If you need synchronization use sych. primitives, java.util.concurrent etc., not thread locals.