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? About a month ago I saw a presentation on Hot Spot and they claim that the synchronized keyword has very little over head (something like 3 extra stack pushed and a lock grab), but exception handling like this can be very expensive because Hot Spot purposely does not optimize exception handling (which means that an exception can cost 100-1000 times longer then the non-excetion code). The only way I could see that this code be faster is if there is a lot of contention. Is there? -- xxxxxxxxxxxxxxxxxxxxxxxx Dain Sundstrom Chief Architect JBossCMP JBoss Group, LLC xxxxxxxxxxxxxxxxxxxxxxxx ------------------------------------------------------- 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