Classloader problem due to Teneo caching mechanism. [message #431679] |
Tue, 21 July 2009 10:12  |
Eclipse User |
|
|
|
Hello Martin,
I am facing classloader problem due to Teneo caching mechanism used in
FieldUtil.java. Teneo is returning already cached objects.
Scenario:
Suppose there is a process layer (say PG1) and two service layers (say S1
& S2), PG1 contains two different methods to load Person domain object
from service S1 and S2 respectively. Suppose both of these services have
the same method (say loadPersonData ()) to load the Person object i.e. I
can load the Person object using S1 as well as S2.
As each service layer and process layer will be packed in separate EAR,
which means they will have their own Class Loader.
We have two Junit test cases and both are trying to load the same Person
(say id=100) by using different services i.e. testcase1 is using the
PG1S1 to load Person while the testcase2 is using PG1S2 to
load the same Person object. In this case, the test case which is executed
first pass the test case successfully, however the other test case fails
to load Person.
Now why one of the test cases is failing is:
1. Teneo is internally caches fields (java.lang.reflect.Field) of a domain
object in FieldUtil.java. Since the same field was loaded and cached by
service S1 in the first testcase, so whenever other test case tries to
load the same object, Teneo return the cached object. Below is the
original and modified snippet from FieldUtil.java:
Original Code:
public static Field getField(Class<?> clazz, String fieldName) {
Field field = (Field) fieldMethodCache.get(clazz.getName() + "." +
fieldName);
if (field != null) {
return field;
}
}
I have commented out the caching mechanism from FieldUtils.java which will
solve this problem.
Modified code:
public static Field getField(Class<?> clazz, String fieldName) {
//Field field = (Field) fieldMethodCache.get(clazz.getName() +
"." + fieldName);
Field field = null;
if (field != null) {
return field;
}
}
BRegards,
Ajay Chauhan
|
|
|
Re: Classloader problem due to Teneo caching mechanism. [message #431687 is a reply to message #431679] |
Tue, 21 July 2009 11:10   |
Eclipse User |
|
|
|
Hi Ajay,
I see why it fails but I am not yet sure yet... How is teneo used here, it appears to be shared by different layers
(otherwise you would not get hit by this, right?). So it may also be a classloading issue in Teneo which should be
solved there.
gr. Martin
Ajay Chauhan wrote:
> Hello Martin,
>
> I am facing classloader problem due to Teneo caching mechanism used in
> FieldUtil.java. Teneo is returning already cached objects.
> Scenario:
> Suppose there is a process layer (say PG1) and two service layers (say
> S1 & S2), PG1 contains two different methods to load Person domain
> object from service S1 and S2 respectively. Suppose both of these
> services have the same method (say loadPersonData ()) to load the Person
> object i.e. I can load the Person object using S1 as well as S2. As each
> service layer and process layer will be packed in separate EAR, which
> means they will have their own Class Loader. We have two Junit test
> cases and both are trying to load the same Person (say id=100) by using
> different services i.e. testcase1 is using the PG1S1 to load
> Person while the testcase2 is using PG1S2 to load the same
> Person object. In this case, the test case which is executed first pass
> the test case successfully, however the other test case fails to load
> Person.
>
> Now why one of the test cases is failing is:
> 1. Teneo is internally caches fields (java.lang.reflect.Field) of a
> domain object in FieldUtil.java. Since the same field was loaded and
> cached by service S1 in the first testcase, so whenever other test case
> tries to load the same object, Teneo return the cached object. Below is
> the original and modified snippet from FieldUtil.java:
>
> Original Code:
>
> public static Field getField(Class<?> clazz, String fieldName) {
> Field field = (Field) fieldMethodCache.get(clazz.getName() + "." +
> fieldName);
> if (field != null) {
> return field;
> }
> �
> �
> �
> }
>
> I have commented out the caching mechanism from FieldUtils.java which
> will solve this problem.
>
> Modified code:
>
> public static Field getField(Class<?> clazz, String fieldName) {
> //Field field = (Field) fieldMethodCache.get(clazz.getName()
> + "." + fieldName);
> Field field = null;
> if (field != null) {
> return field;
> }
> �
> �
> �
> }
>
> BRegards,
> Ajay Chauhan
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
Powered by
FUDForum. Page generated in 0.06364 seconds