-
1. Re: TransactionLocal: How to use it?
adrian.brock Feb 28, 2007 12:32 PM (in response to ypsilon)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. -
2. Re: TransactionLocal: How to use it?
ypsilon Mar 16, 2007 6:42 AM (in response to ypsilon)Hi adrian
thanks a lot for your reply (unfortunatly I wasn't watching this thread so I stumbled upon your reply so late).
Meanwhile I implemented a similar functionality by using an XAResource. Since this is kind of ugly (but works fine ;-) ) I consider removing that in order to slim the transaction processing.
What I actually did not understand is your second concern. (I am not too familiar with the internals of classloading.) Can you point me to a scenario where the classloader would lead to a ClassCastException? Does this only occur upon redeployments?
Thanks again
Greetings
PeeR -
3. Re: TransactionLocal: How to use it?
adrian.brock Mar 19, 2007 2:01 PM (in response to ypsilon)"ypsilon" wrote:
Can you point me to a scenario where the classloader would lead to a ClassCastException? Does this only occur upon redeployments?
Correct, in generalpublic class DoesntGetRedeployed { public static Collection staticCollection = ...; } public class CodeThatGetsRedeployed { public void doSomethingBeforeRedeploy() { DoesntGetRedeployed.add(this); } public void doSomethingAfterRedeploy() { Object x = DoesntGetRedeployed.get(); // x instanceof CodeThatGetsRedeployed == false } }
Although, I'd be impressed if you could come up with such a situation
WITHIN A TRANSACTION! :-) -
4. Re: TransactionLocal: How to use it?
ypsilon Apr 17, 2007 10:35 AM (in response to ypsilon)"adrian@jboss.org" wrote:
Although, I'd be impressed if you could come up with such a situation
WITHIN A TRANSACTION! :-)
I sure did some fancy stuff, but no I would rather not come up with such a situation.
Again, thanks for the helpful information.
Greetings
PeeR