0

I have a large in-memory cache inside my Java application, which is being filled after application starts. It's makes redeployments extremelly expensive and slowers development process.

To solve the problem I'd like to outsource the cache to a separate Java process. What is the fastest way to connect two Java processes on Linux?

Denis Kulagin
  • 8,472
  • 17
  • 60
  • 129
  • create a `Socket` connection between them – ControlAltDel Dec 16 '15 at 12:10
  • @ControlAltDel, OP has *large* in-memory cache – AlexR Dec 16 '15 at 12:14
  • 1
    What kind of cache are you using? Some third party or just Map? – AlexR Dec 16 '15 at 12:15
  • @AlexR I didn't get your comment. I understand that OP has a large in-memory cache. But why do you think that using sockets to connect two processes is not a good solution? – ControlAltDel Dec 16 '15 at 12:18
  • @ControlAltDel, you are right that in low-level it is socket. However OP probably does not want to implement socket level code himself. Moreover probably using socket when accessing each piece of large cache is very ineffective, so probably he needs higher-level, "smarter" solution/library. – AlexR Dec 16 '15 at 12:21
  • possible duplicate of http://stackoverflow.com/questions/14580337/most-efficient-performance-wise-for-inter-jvm-communication – Sharon Ben Asher Dec 16 '15 at 12:32
  • or this http://stackoverflow.com/questions/10942427/how-to-have-2-jvms-talk-to-one-another amazing what google can find you – Sharon Ben Asher Dec 16 '15 at 12:35

1 Answers1

1

As a fastest solution I'd recommend you to use Hazelcast. They support distributed maps. You can define simple, 2 nodes cluster, so when both your processes are up the date will be shared, when one of them is going down the data will be still in the memory of dedicated process, when the main process is up again the data will be shared again.

The only thing that you have to change in your code is the line where you create instance of your map. You have to use the Hazelcast API instead of new HashMap<>().

AlexR
  • 114,158
  • 16
  • 130
  • 208