Question

I'm using JBossCache 'Malagueta' 3.2.0.GA

I faced with strange issue in production environment, sometimes writes to jboss cache do not work properly. I tried to reproduce this situation with simple java application

public static void testCache() {
    Cache cache = new DefaultCacheFactory().createCache(false);
    cache.create();
    cache.start();
    final Node node = cache.getRoot().addChild(Fqn.fromString("/child1"));
    int threadsCount = 20;
    final CyclicBarrier b = new CyclicBarrier(threadsCount);
    for (int i = 0; i < threadsCount; i++) {
        final long j = i;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    b.await();
                    String name = RandomGenerator.getRandomName(4);
                    node.put(j, name);
                    String nameFromCache = (String) node.get(j);
                    if (!name.equals(nameFromCache)) {
                        System.out.println("error");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}

From time to time, this test output "error", which i run from static void main fail. 1 of 3 runs return "error" msg. It simply return null. I can't reproduce it on every machine.

Any clue ?

Was it helpful?

Solution 2

Update to cache 3.2.5 solved this problem. Seems like it's jboss cache bug.

OTHER TIPS

You code looks fine so it may be that the Jboss cache is asynchronous. I see nothing in the Javadocs that guarantees when the cache would be updated.

I know in many distributed cache implementations, a put operation is written out to the wire and even the local instance of the cache is updated from the inbound message, not directly through a local call. This allows caches to appropriately serialize their updates so that updates from multiple machines are processed in the correct order on all nodes in the network.

One thing to try is to set the cache to be LOCAL. Something like the following:

Configuration config = new Configuration();
config.setCacheMode(LOCAL);
Cache cache = new DefaultCacheFactory().createCache(config, false);
...

If that does not fail then I suspect I am correct. Even if it does still fail I may be correct since the LOCAL modes may still have a loopback network stack underneath or something.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top