Bob Hanson wrote:
> pps. The following is more elegant and also works:
>
>   static Boolean[] testInit = new Boolean[1];
>   private void initialize() {
>     if (testInit[0] != null) {
>       while (!testInit[0].booleanValue()) {
>         try{
>           Thread.sleep(10);
>         } catch(Exception e) {
>           System.out.println("geodesic constructor error "+e);
>         }
>       }
>       return;
>     }
>     testInit[0] = Boolean.FALSE;
> ...
>     System.out.println("geodesic initialization completed");
>     testInit[0] = Boolean.TRUE;
>   }
>
> It takes advantage of the fact that static testInit[0] has THREE 
> possible values: null, false, and true.
> This is what I'm going with for now.
>   

That won't work in every situation :
- thread 1 executes "if (testInit[0] != null)" and finds that it evals 
to false
- thread 2 executes "if (testInit[1] != null)" and finds that it evals 
to false also
- thread 1 goes on
- thread 2 goes on

You could try using a synchronization on a variable.

Check on the web for the Singleton pattern and multi-threading problems, 
I think solutions for it will also work for your problem.


Nico




_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to