IBM Support

ClassCastException when using DynaCache across web applications

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.

[{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Dynamic Cache","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF012","label":"IBM i"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.5;8.0;7.0;6.1","Edition":"Advanced;Base;Developer;Enterprise;Express;Network Deployment;Single Server;WebSphere Business Integrations Server Foundation","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SS7K4U","label":"WebSphere Application Server for z\/OS"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":null,"Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"6.1;6.0","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21261441