The problem with all these 'tricks' to avoid synchronization is that they rely on all sorts of assumptions about both the compiler and the underlying memory model. Unfortunately the JVM spec is such that you really can't make these assumptions.
See http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html and in particular Doug Lea's thoughts on syncronization and the Memory model.. http://gee.cs.oswego.edu/dl/cpj/jmm.html On Wed, Jul 17, 2002 at 05:21:07PM +0100, Kevin Conner wrote: > > Ole Husgaard wrote: > > > + // Using the construct > > > + // try { > > > + // txCapsule.doSomething(); > > > + // } catch (NullPointerException ex) { > > > + // throw new IllegalStateException("No transaction."); > > > + // } > > > + // may look like bad programming style, but it is > > needed to avoid to > > > + // synchronize on these methods. If we used a construct like > > > + // if (txCapsule == null) > > > + // throw new IllegalStateException("No transaction."); > > > + // txCapsule.doSomething(); > > > + // we can get spurious NullPointerExceptions when > > racing with the > > > + // transaction completion. > > > + > > > > > > public void commit() > > > throws RollbackException, > > > @@ -68,9 +83,11 @@ > > > java.lang.IllegalStateException, > > > SystemException > > > { > > > - if( txCapsule == null ) > > > + try { > > > + txCapsule.commit(); > > > + } catch (NullPointerException ex) { > > > throw new IllegalStateException("No transaction."); > > > - txCapsule.commit(); > > > + } > > > > Interesting... Is this actually faster then synchronizing? Have you > > measured it? > > How about: > > public void commit() > { > final TxCapsule localTxCapsule = txCapsule ; > if (localTxCapsule == null) > throw new IllegalStateException("No transaction.") ; > localTxCapsule.commit() ; > } > > Kev > > Kevin Conner > Orchard Information Systems Limited > Newcastle Technopole, Kings Manor > Newcastle Upon Tyne, NE1 6PA. United Kingdom > Registered in England, Number 1900078 > Tel: +44 (0) 191-2032536 Fax: +44 (0) 191 2302515 > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Jboss-development mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-development > > -- regards Neale Swinnerton ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development