prasoonblueluck
prasoonblueluck

Reputation: 85

Taking dump of hashmap from memory, for a java process

I have a Java process which has been running for over a week. In the process, I have been processing some data and have been storing some intermediate result into a hashmap in memory.

Now, I need to stop the process due to some bugs in the code. But if i kill the process, then i lose the data in the hashmap n will have to reprocess it again, the next time i run the code.

Is their a way by which i can take a dump of the hashmap present in the memory ?

Upvotes: 0

Views: 279

Answers (2)

DNA
DNA

Reputation: 42586

You can use JConsole, which is included with the Standard JDK, or visualvm to attach to an already-running process and trigger a heap dump.

However, as Peter said, actually reading this dump is not going to be fun unless you can find a tool to assist you.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533442

You can trigger a memory dump which you can read with various tools such as profilers. This is very difficult to read and I have never heard of some one using this to restart a program.

Restarting a program is not something you can do as an afterthought, it needs to designed into your application and thoroughly tested. One way people get around having to worry about this issue is to use a database. This is because databases are, designed and tested professionally, to be restarted without losing data.

Upvotes: 1

Related Questions