JBOSS and ThreadLocal
vaidya1973 May 23, 2011 4:03 PMHi,
I have a scenario wherein I have a jersey servlet talking to ejbs within the same ear . I needed to pass in some session info. from the REST servlets to the ejbs and one way in which I did this was to use ThreadLocal variables, populated from within a ContainerFilter (servlet filter). The jersey resources then does a lookup of the ejbs and makes the method calls , within the method call at one pt I need the recorded date but when i look for it , it goes to the initialValue , even though the thread id is the same and it should get the value from the ContainerFilter that i used on its way in.
This set up used to work but i had to introduce some things in the jboss.xml for some other issue and am wondering whether that is causing the ThreadLocal values to get messed up. I introduced a section on enterprise-beans as follows
<enterprise-beans>
<session>
<ejb-name>EJBService</ejb-name>
<ignore-dependency>
<injection-target>
<injection-target-class>Target class </injection-target-class>
<injection-target-name>Target Service </injection-target-name>
</injection-target>
</ignore-dependency>
</session>
</enterprise-beans>
Following is my Entity Auditor..
public class EntityAuditor implements Serializable{
private static InheritableThreadLocal<HistoryInfo> auditInfo= new InheritableThreadLocal < HistoryInfo > () {
@Override protected HistoryInfo initialValue() {
System.out.println("Initialized");
return new HistoryInfo();
}
};
public static void setRecordedDate(Date theRecordedDate) {
System.out.println("Current Thread Id"+Thread.currentThread().getId());
HistoryInfo audInfo=auditInfo.get();
audInfo.setRecordedDate(theRecordedDate); //Setting this to the recorded date on the way in..
auditInfo.set(audInfo);
}
public static Date getRecordedDate() {
System.out.println("Current Thread Id"+Thread.currentThread().getId());
HistoryInfo audInfo=auditInfo.get(); // this one should not go to initialValue method but it goes..
if(audInfo!=null)
{
return audInfo.getRecordedDate();
}
return null;
}
}
Has anyone seen this issue?