Java相当于Ant的Java任务中的fork? [英] Java equivalent of fork in Java task of Ant?

查看:73
本文介绍了Java相当于Ant的Java任务中的fork?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ant Java任务提供了fork参数,根据定义如果启用则触发另一个VM中的类执行" .由于要处理大量数据,因此设置此参数可以避免Java堆空间不足.
我们希望能够通过Java类执行相同的操作.实现fork提供的功能的最佳方法是什么?

Ant Java task provides fork parameter, which, by definition "if enabled triggers the class execution in another VM". As we are dealing with a large amount of data, setting this parameter saved us from running out of Java heap space.
We want to be able to do the same through a Java class. What would be the best way to achieve the functionality as provided by fork?

推荐答案

执行另一个Java进程.例如,通过使用ProcessBuilder类.

Execute another java process. By using ProcessBuilder class, for example.

http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html

您可以根据需要运行任意数量的工作进程.让他们拥有一个单独的主班,从该主班执行任务,并在任务完成时退出.

You can run as many worker processes as you wish. Make them having a separate main class, doing their tasks from that main class, and quiting when their task is completed.

您必须弄清楚它们的类路径以及Java二进制文件在系统上的位置,但这是可行的.

You'll have to figure out their classpath, and the location of java binary on the system, but that's doable.

我认为当它们通过Process.waitFor()完成时,您甚至可以得到通知.

I think you can even be notified when they complete via Process.waitFor().

这篇关于Java相当于Ant的Java任务中的fork?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆