Troubleshooting
Problem
ClassCastException occurs when application A stores an object in DynaCache instance and application B retrieves the object from Dynacache and attempts to cast it to proper type.
Resolving The Problem
By default, each application will have a separate ClassLoader. If you have common classes visible to web application classloader, then you may encounter ClassCastExceptions.
To fix this problem, there are two recommended solutions:
1. Convert the object into byte array stream and store in DynaCache. Application must serialize the object before adding in cache and de-serialize after retrieving from cache. This is the preferred method.
2. Create a shared library for the common classes and associate the shared library for a classloader at server level. This will avoid ClassLoader conflicts and will not cause ClassCastExceptions. The disadvantage of using this technique is that the class needs to be visible at server level. This may not be preferred if the same type of class needs to be present at various versions in different applications.
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21261441