开发者

Subtask in its own heap space

In Java, supposing you want to run a task in its own heap space (e.g. so that it can crash with an out of memory error without affecting the rest of your program), you can use Runtime.exec to load the JVM and the relevant by开发者_运维问答te code files from the file system and redo all the work that needs to be done to start up a Java program from scratch.

This is somewhat high overhead, if the tasks you want to run are fairly fine-grained. Is there any lower overhead way to do it?


Since you'd be anyways doing interprocess communication, is looking into RMI an option for you? With RMI daemon, you can have pooled processes to which you can submit jobs and get back results. This also relieves you of manually managing spawning VM's etc.

Or look into a job queue based solution in which the main VM creates job packets and dumps them on the queue which is monitored by one or more processes. Anyways, AFAIK, the most fine grained way of doing these is not spawning VM's on demand.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜