What version of the product are you using? 2.5.jar On what operating system? Linux 64 bit
Tell me more...
I put the memcached-2.5.jar under /tomcat/lib/ It worked fine for puting the object to the cache. But got the following error when trying to get the object. The DATA model object is located in the same web application but a different package. What went to wrong? Any idea on solving this issue? Thanks a lot.
Instance: org.psisb.kb.spymemcache.KBCache@5ca3ce3f 2010-10-08 21:23:10.236 WARN net.spy.memcached.transcoders.SerializingTranscoder: Caught CNFE decoding 690 bytes of data java.lang.ClassNotFoundException: org.kb.ws.summary.model.Data at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at net.spy.memcached.transcoders.BaseSerializingTranscoder.deserialize(BaseSerializingTranscoder.java:100) at net.spy.memcached.transcoders.SerializingTranscoder.decode(SerializingTranscoder.java:66) at net.spy.memcached.transcoders.TranscodeService$1.call(TranscodeService.java:36) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at net.spy.memcached.transcoders.TranscodeService$Task.run(TranscodeService.java:83) at net.spy.memcached.transcoders.TranscodeService$Task.get(TranscodeService.java:69) at net.spy.memcached.internal.GetFuture.get(GetFuture.java:38) at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:917) at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:939)
Comment #1
Posted on Mar 24, 2011 by Quick Elephanti use grails 1.3.7,memcached-2.5.jar, domain class implements Serializable. it will show this warn ..
Comment #2
Posted on Oct 27, 2011 by Happy PandaHi, I had this issue in the past and I found a solution. The occurs because the memcached client it is loaded using a classloader and the serialized object class is loaded using another classloader. To fix this you must pass to the memcahed client connector factory a custom transcoder.
public class CustomSerializingTranscoder extends SerializingTranscoder{
@Override
protected Object deserialize(byte[] bytes) {
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
ObjectInputStream in = null;
try {
ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
in = new ObjectInputStream(bs) {
@Override
protected Class<?> resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException {
try {
return currentClassLoader.loadClass(objectStreamClass.getName());
} catch (Exception e) {
return super.resolveClass(objectStreamClass);
}
}
};
return in.readObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
closeStream(in);
}
}
private static void closeStream(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Comment #3
Posted on Nov 30, 2011 by Happy GiraffeNope, did not work for me. I changed Object value = cache.get(key) ; To Object value = cache.get(key, SuperCache.customTranscoder) ; And below is the code for CustomSerializingTranscoder What am I doing wrong. The exception is crazy, its in completely different part of the code.
import java.io.ByteArrayInputStream; import java.io.Closeable; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectStreamClass;
import net.spy.memcached.transcoders.SerializingTranscoder;
public class CustomSerializingTranscoder extends SerializingTranscoder{
@Override
protected Object deserialize(byte[] bytes) {
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
ObjectInputStream in = null;
try {
ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
in = new ObjectInputStream(bs) {
@Override
protected Class<ObjectStreamClass> resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException {
try {
return (Class<ObjectStreamClass>) currentClassLoader.loadClass(objectStreamClass.getName());
} catch (Exception e) {
return (Class<ObjectStreamClass>) super.resolveClass(objectStreamClass);
}
}
};
return in.readObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
closeStream(in);
}
}
private static void closeStream(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Comment #4
Posted on Jan 11, 2013 by Grumpy CamelI had the same issue on Glassfish 2.1 and the comment 2 worked like a charm!
Thank you
Comment #5
Posted on Feb 5, 2013 by Happy HippoTo save you some time searching about how you will apply the custom class in comment # 2 ... here's some sample code which shows that you can just add .setTranscoder(new CustomSerializingTranscoder()) when you're building the client:
MemcachedClient mc = new MemcachedClient( new ConnectionFactoryBuilder() .setTranscoder(new CustomSerializingTranscoder()) // use this line .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) ...
Comment #6
Posted on Aug 16, 2013 by Helpful MonkeyComment deleted
Comment #7
Posted on Aug 28, 2013 by Helpful MonkeyIf you are using spymemcached alone (without MSM), just place the spymemcached.jar in the WEB-INF/lib folder inside your webapp, and not in /$CATALINA_HOME/lib/ and it will be fine.
Solution 2 + 5 works, but if possible just moving the jar is preferable.
Comment #8
Posted on Mar 1, 2014 by Quick Ox2 worked for me!
Comment #9
Posted on Apr 17, 2014 by Happy Dog2 answer is correct. I fix this bug follow his instruction. Thank you very much~^0^~
Comment #10
Posted on Aug 31, 2014 by Swift Dogi had the same issue and comment #7 worked for me Thanks
Comment #11
Posted on Oct 9, 2014 by Helpful CamelNope, didn't work for me. I use 1 memcached with multi project
Status: New
Labels:
Type-Defect
Priority-Medium