开发者

It's possible clear/free resources to restart some processing without restart application?

I'm doing a webcrawler that works automatically. At certain point, I want to stop开发者_JAVA技巧 it, change some settings and restart the crawling.

I'm worried about the resources. I can free the objects that I created, but I don't know about the objects that Java uses. Doing some debug, I see that has much more classes than in the start of application.

There is some technic/way/method to free these? I need to worry about this?


I think you need to understand better which objects are created and which remain in memory. A profiler tool can help you - many of them let you take a snapshot of the memory, perform some operation, and then compare the current state with the snapshot. This highlights the possible memory leaks.

Also, make sure you explicitly run the garbage collector before even looking at the memory state - otherwise you might see lots of objects which are actually unreferenced and will be collected by the next GC.

I wouldn't worry about resources allocated by the JVM. As long as you free all the resources that you allocate, you should be fine - and a profiler will help you make sure that you indeed free them all.


There is some technic/way/method to free these?

In theory, you could serialize the application's key data structures, restart, and reload the serialized data structures.

In practice, the application has to be written to do this. You would probably have to rearchitect an existing (non-restartable) application to make this possible. So, a better idea would be to store important application state in database tables so that you can stop and restart at will ... and survive an application crash or power failure.

I need to worry about this?

That's up to you / depends on your requirements. But I'd avoid implementing an application that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜