Over a million developers have joined DZone.

JBossCache - Unmarshalling Cached Objects Across JVMs

DZone's Guide to

JBossCache - Unmarshalling Cached Objects Across JVMs

· ·
Free Resource
JBossCache doesn't natively allow you to put and get objects across classloaders, so we need to marshal and unmarshal the objects with org.jboss.invocation.MarshalledValue.

private TreeCacheMBean cache;

void put(String path, Object key, Object value) throws Exception {
  cache.put(path, key, getMarshalledValue(value));

Object get(String path, Object key) throws Exception {
  return getUnMarshalledValue(cache.get(path, key));

private Object getUnMarshalledValue(Object value) throws IOException, ClassNotFoundException {
  return ((MarshalledValue) value).get();
private Object getMarshalledValue(Object value) throws IOException {
  return new MarshalledValue(value);

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}