1

I am using a map with Hazelcast :

//When I do :

map.put(gen.newId(), myObject);

myObject is a very complex object and does not implements Serializable.

I thought that putting the config like below was enough for not having to implement serializable :

<map name="myMap">
    <in-memory-format>OBJECT</in-memory-format>   
</map>

The Hazelcast doc says : http://docs.hazelcast.org/docs/3.5/manual/html/entryprocessor.html "When it is stored as an object (OBJECT format), then the entry processor is applied directly on the object. In that case, no serialization or deserialization is performed"

Thanks for any suggestion.

Zitun
  • 388
  • 1
  • 4
  • 13

2 Answers2

4

Unfortunately the object will always be deserialized when the map.put is called, no matter the in memory format. This is because normally there are backups and they need to receive a copy as well. So in this case your only way out is to make your object 'serializable'. You can use Java serialization, but you can also rely on something like Kryo to deal with complex object graphs.

pveentjer
  • 10,545
  • 3
  • 23
  • 40
  • Another reason is that Hazelcast currently doesn't know the difference between a mutable and immutable object. So imagine we would track the reference to your object, then now the object is potentially being shared between threads. Then you run in all kinds of nasty race conditions and visibility problems. Apart from that imagine doing some logic on your shared object and you change some fields, and eventually run into some exception. Now your object, since it is shared, is half modified and leads to a permanently inconsistent representation. – pveentjer Nov 04 '15 at 04:32
1

I think you could also use more efficient hazelcast specific solutions. Here is a comparison table of the solutions. Portable has been working for me but is a pain in the ass to implement and maintain for big objects. DataSerializable is a more easy solution and looks a lot like Parcelable from Android.

jobbert
  • 3,297
  • 27
  • 43