[jboss-user] [JCA/JBoss] - Re: TransactionLocal: How to use it?

adrian@jboss.org do-not-reply at jboss.com
Wed Feb 28 12:32:02 EST 2007


TransactionLocal works the same way as ThreadLocal,
just replace the notion of thread with transaction.

Like thread local, if you want to pass references under the wire of an interface
you need a singleton (or some way to get the same instance).


  | public MySingleton
  | {
  |    public static final TransactionLocal singleton = new TransactionLocal();
  | }
  | 

Such singletons have a number of problems:

1) Unless you implement something a lot less naive than the above
the information in the singleton is public and so could cause security issues
if the information is sensistive
or just broken behaviour if somebody modifies the data unexpectedly/maliciously.

2) They lead to breakage of the type system (ClassCastException)
in more complicated classloading schemes when not deployed correctly.

3) Singletons that store state usually lead to memory leaks unless handled correctly.
At least with the TransactionLocal, the data is "tidied up" when the tranasction ends.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4023837#4023837

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4023837



More information about the jboss-user mailing list