Re: user manual code example race condition

Mark Evenson <[email protected]>
Newsgroups gmane.editors.j.devel
Message-ID <14FEDAF7-63F5-464F-86B6-7931793F3369__1100.14712424658$1552298449$gmane$org@panix.com>

> On Mar 11, 2019, at 06:38, dingd <[email protected]> wrote:
> 
> this is recommended in the manual, it contains a race condition.
> 
> Interpreter interpreter = Interpreter.getInstance ();
> if ( interpreter == null ) {
> 	interpreter = Interpreter.createInstance ();
> }
> 
> getInstance and createInstance should be swapped.

Since both Interpreter.getInstance() and Interpreter.createInstance() are
methods synchronized on the same object monitor, I don’t see that there is a
race condition here.  Could you explain a little more about your reasoning
and/or experience with the race condition?

-- 
"A screaming comes across the sky.  It has happened before but there is nothing 
to compare to it now."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.