> > > Miguel wrote: > >> Kent wrote: >> >> >>>(except for static final >>>variables, which are of course okay). >> >> >> Correct >> > I'm not so sure. Why are these not a problem?
You are correct ... For primitive types 'final static' is not a problem. For primitive types, 'final static' is the recommended mechanism for declaring constants in Java. For object types the data that is contained in the object may require synchronization, but the variable itself does not ... a subtle distinction. For all practical purposes, 'final static' does not eliminate threading issues with complex objects. > I'm pretty sure it was a > final static array def that led to the problems I fixed in isosurface. > Maybe it wasn't final.... > <http://svn.sourceforge.net/viewcvs.cgi/jmol/branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java?r1=5206&r2=5207> > > Maybe it was just the nonfinal ones that were causing the problem. I'm > certain that the following was for SURE a problem, but I think it was > probably more than that. > > static Vector3f[] pixelVertexVectors = new Vector3f[4]; > > Why would final make a difference here -- the pointer to the object > may be final, but the contents of the object are changeable by > individual threads. The contents of the object could be changed. In this case, I suspect that you either want it to be final (to ensure that nobody ever changes it), or you do not want to initialize it. That is, it probably should be 'final static' or not initialized or non-static. > You really think that > > final static Matrix3f matXyzToPlane = new Matrix3f(); > > can't cause a problem when a new thread loads it? The initialization is only going to happen when the class loads. The class is only going to get loaded once. The first thread to reference the class will load the class. The second thread will not reload the class because the class was already loaded. So the static variables will not get re-initialized and overwritten. Miguel _______________________________________________ Jmol-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jmol-developers
