Closed GoogleCodeExporter closed 8 years ago
Hi Benjamin.
Can you provide a stack trace and output from the logs? We need to know if the
problem occurs in the serialization side before the object is even sent, or
after the object is received and the remote machine requests the class bytecode
from the local side.
Multithreading is definitely supported. There might be something strange going
on with context class loaders or something.
Original comment by ni...@npgall.com
on 24 Nov 2014 at 11:07
No Problem! When I run my code with threading and simple object migration, I
will get one of the two errors. Both having to do with serialization I believe.
As soon as I take out threads or the migration, everything works, unless I
missed something in my debugging.
EXCEPTION #1
Exception in thread "Thread-0" java.lang.NoClassDefFoundError:
com/googlecode/mobilityrpc/quickstart/QuickTask
at Jambient.Ambient.migrate_runone(Ambient.java:138)
at jambientmovitatingexample.JambientMovitatingExample.run(JambientMovitatingExample.java:113)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException:
com.googlecode.mobilityrpc.quickstart.QuickTask
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
EXCEPTION #2
Exception in thread "main" java.lang.IllegalStateException: Exception
serializing object to KRYO format:
com.googlecode.mobilityrpc.quickstart.QuickTask$SessionReleasingRunnable@de96c95
at com.googlecode.mobilityrpc.session.impl.MobilitySessionImpl.serialize(MobilitySessionImpl.java:508)
at com.googlecode.mobilityrpc.session.impl.MobilitySessionImpl.execute(MobilitySessionImpl.java:81)
at com.googlecode.mobilityrpc.session.impl.MobilitySessionImpl.execute(MobilitySessionImpl.java:75)
at com.googlecode.mobilityrpc.quickstart.QuickTask.execute(QuickTask.java:57)
at com.googlecode.mobilityrpc.quickstart.QuickTask.execute(QuickTask.java:44)
at Jambient.Ambient.migrate_runall(Ambient.java:107)
at jambienttester.JambientTester.main(JambientTester.java:50)
Caused by:
com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.SerializationException:
Unable to serialize object of type:
com.googlecode.mobilityrpc.quickstart.QuickTask$SessionReleasingRunnable
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:493)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.ObjectBuffer.writeClassAndObject(ObjectBuffer.java:230)
at com.googlecode.mobilityrpc.serialization.impl.KryoSerializer.serialize(KryoSerializer.java:139)
at com.googlecode.mobilityrpc.session.impl.MobilitySessionImpl.serialize(MobilitySessionImpl.java:502)
... 6 more
Caused by:
com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.SerializationException:
Unable to serialize object of type: Jambient.Ambient
Serialization trace:
childList (Jambient.Ambient)
parent (Jambient.Ambient)
this$0 (Jambient.Ambient$1)
wrapped
(com.googlecode.mobilityrpc.quickstart.QuickTask$SessionReleasingRunnable)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:493)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.CollectionSerializer.writeObjectData(CollectionSerializer.java:86)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:489)
... 9 more
Caused by:
com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.SerializationException:
Unable to serialize object of type: Jambient.Ambient
Serialization trace:
siblingList (Jambient.Ambient)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:493)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.CollectionSerializer.writeObjectData(CollectionSerializer.java:86)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:489)
... 19 more
Caused by:
com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.SerializationException:
Serialization trace:
classes (sun.misc.Launcher$AppClassLoader)
contextClassLoader (java.lang.Thread)
t_in (Jambient.Ambient)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:191)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.ReferenceFieldSerializer.writeObjectData(ReferenceFieldSerializer.java:52)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:489)
... 23 more
Caused by: java.util.ConcurrentModificationException
at java.util.Vector$Itr.checkForComodification(Vector.java:1156)
at java.util.Vector$Itr.next(Vector.java:1133)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.CollectionSerializer.writeObjectData(CollectionSerializer.java:85)
at com.googlecode.mobilityrpc.lib.com.esotericsoftware.kryo.serialize.FieldSerializer.writeObjectData(FieldSerializer.java:175)
... 29 more
Java Result: 1
Original comment by benjamin...@gmail.com
on 24 Nov 2014 at 4:26
Based on that info I think this might be an issue in your code, not
Mobility-RPC actually. But you have a few options to solve it...
EXCEPTION #1
In this example, com.googlecode.mobilityrpc is not mentioned in the stack trace
at all. It seems your application tries to call a class in Mobility-RPC, but
the Mobility-RPC jar file is somehow missing from your class path (?) This is a
strange problem, I don't know what it is but your application is not set up
correctly in this case.
EXCEPTION #2
In this case it looks like you are trying to serialize a java.util.Vector on
the local machine so that it can be sent to the remote machine, but some other
threads on the local machine continue to modify the vector at the same time
while it is being iterated by the serializer, which caused the vector itself to
throw a ConcurrentModificationException into the serializer.
This is a limitation of java.util.Vector itself. It is a "synchronized" data
structure, not a "concurrent" data structure. It can be used by multiple
threads in an application, but only one thread can access it at a time. Vector
automatically enforces this in most cases (most of its methods are
synchronized), with one important exception: iteration. See
http://stackoverflow.com/questions/1775717/explain-synchronization-of-collection
s-when-iterators-are-used - if the vector will be iterated while other threads
try to modify it, the application programmer needs to manually synchronize on
the vector while it is being iterated.
You can avoid this problem by having your code synchronize on the vector,
before you try to send the object to the remote machine. Another workaround
would be to use a CopyOnWriteArrayList in your code instead of a Vector, which
would be a drop-in replacement (but would have its own pros and cons).
Vector is basically not a very modern data structure so I'd recommend that you
use a different data structure (which doesn't require synchronization), if
possible.
Original comment by ni...@npgall.com
on 24 Nov 2014 at 5:59
Aw makes sense. I didn't think about the second one having the concurrent
modification. As far as the first one, I thought the same thing and am fairly
certain it is all set up correctly, I have the jar imported and everything
works without threads. I will check it out some more. Thanks for your help! Its
a great library!
Original comment by benjamin...@gmail.com
on 24 Nov 2014 at 6:05
Also, I am not using a Vector, but an ArrayList, which is definitely a modern
data structure. Would that still cause this issue?
Original comment by benjamin...@gmail.com
on 24 Nov 2014 at 6:07
Yes ArrayList would be susceptible to that problem also.
You basically need a collection which supports concurrent iteration. Take a
look at the concurrent package, you should find a few options there:
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/package-summary.ht
ml
I'll close this ticket. Feel free to post details of the first problem in the
forum if you get stuck, I'll take a look there:
http://groups.google.com/group/mobility-rpc-discuss
Original comment by ni...@npgall.com
on 24 Nov 2014 at 11:18
Awesome. Thanks for your help!
Original comment by benjamin...@gmail.com
on 24 Nov 2014 at 11:30
Original issue reported on code.google.com by
benjamin...@gmail.com
on 24 Nov 2014 at 3:46