Thank You Pramod and Thomas for all your inputs. 

Hi Pramod,
Jira that Thomas
referred seem to be the one inline with what you suggested as a possible
solution. I see there is new class (new in malhar
and not present with 3.7.0 version that I am using) which is doing the work,
though its not related to this particular issue

Regarding my statement of Kryo not working with LinkedHashMap, to put it
precisely,/ it doesn't work for a class that extends LinkedHashMap/. In my
case its LRUCache class. It does work with standard LinkedHashMap and I
could verified this with past few version of kryo. Below is the class i
tested with

public class KryoSerDeTest {
  public static void main(String[] args) throws FileNotFoundException {
    TestClass clazz = new TestClass();
    clazz.getCache().put("ABC", "ABCDE");
    clazz.getCache().put("GHI", "GHIJK");

    Kryo kryo = new Kryo();
    Output output = new Output(new FileOutputStream("file.bin"));
    kryo.writeObject(output, clazz);
    Input input = new Input(new FileInputStream("file.bin"));
    TestClass clazz1 = kryo.readObject(input, TestClass.class);


class TestClass {
  LRUCache<String, String> cache;

  public TestClass() {
    cache = new LRUCache<String, String>(10, false);

  public LRUCache<String, String> getCache() {
    return cache;

  public void setCache(LRUCache<String, String> cache) {
    this.cache = cache;

class LRUCache<K, V> extends LinkedHashMap<K, V> {

  private static final long serialVersionUID = 1L;
  public int capacity; // Maximum number of items in the cache.

  public int getCapacity() {
    return capacity;

  public void setCapacity(int capacity) {
    this.capacity = capacity;

  public LRUCache() {

  public LRUCache(int capacity, boolean accessOrder) {
    super(capacity + 1, 1.0f, accessOrder); // Pass 'true' for accessOrder.

  public boolean removeEldestEntry(Map.Entry<K, V> entry) {
    return (size() > getCapacity());

In the above example, if you replace all references of LRUCache from
TestClass with LinkedHashMap then everything works but not with LRUCache

I will update my workaround with your suggestion


View this message in context:
Sent from the Apache Apex Users list mailing list archive at

Reply via email to