I 've always used
(Example: take something from a queue if present, or else construct new instance).
I want to use this for a common-code library class (where I have no idea if it might be used in a multi-thread app).
I find that the use of synchronized(,) is now deprecated in JVM and not supported in JS.
The @Synchronized annotation also cannot be used.
Is there a technique which I can use in common code and will ensure single-thread access to critical code when on a JVM / Native platform?