However you access them, the ThreadLocal variable should be static, otherwise odd things occur when you have multiple instances of the class holding the ThreadLocal.

You almost always want to to override the intialValue() method of the ThreadLocal class.

On 02/21/2015 10:42 PM, Archie Cobbs wrote:
On Sat, Feb 21, 2015 at 6:33 PM, Holger King <holgerk...@gmx.net <mailto:holgerk...@gmx.net>> wrote:

    So, when using a ThreadLocal you would declare it as "public
    static" to allow accessing the added connection object in the
    target code, here the "FSIdmAdaptor"?


That would work. More commonly you make it private and provide access via a static method e.g.

public static Connection getCurrentConnection()
throws IllegalStateException { // if no connection is set in the current thread

For lots of examples look at Spring, e.g., TransactionAspectSupport <http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-tx/4.1.3.RELEASE/org/springframework/transaction/interceptor/TransactionAspectSupport.java#TransactionAspectSupport>.

-Archie

--
Archie L. Cobbs


_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to