2

I am trying to share a concurrent hashmap between applications on a Glassfish (v2) server.

First question, is it at all possible? Secondly, if it is, any suggestions?

What I am trying to achieve is a memory store (cache?) which can be quickly referenced and updated by different components on the same instance. Implementation is a standard key/value set.

Thanks in advance!

NubieJ
  • 575
  • 2
  • 9
  • 21

5 Answers5

2

Sounds like you want a distributed cache. I'd recommend looking at Ehcache and this documentation on cache topologies.

Greg Case
  • 3,200
  • 1
  • 19
  • 17
1

I think maybe you can take a look at Hazelcast project.

roy
  • 26
  • 1
1

I also recommend Hazelcast. It is deadly simple to use and here some comparison

Community
  • 1
  • 1
enesness
  • 3,123
  • 5
  • 31
  • 33
0

What worked for me a long time ago was placing the collection as a singleton in a library which is shared across all applications. This way the library is loaded once and all application use that copy (and its collection)

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

If you are talking about 2 "applications" in the same JVM then it should certainly be possible. If they are in the same ClassLoader then you should be able to do:

public class MapHolder {
    private static final ConcurrentHashMap<String, String> cache =
        new ConcurrentHashMap<String, String>();

    public static ConcurrentHashMap<String, String> getCacheSingleTon() {
        return cache;
    }
}

Then each of your modules can say something like:

public class Foo {
    private ConcurrentHashMap<String, String> cache =
        MapHolder.getCacheSingleTon();
}

This said, I'm not experienced with Glassfish. They may already have caching modules that are available.

Gray
  • 115,027
  • 24
  • 293
  • 354