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
?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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.
You'll have to figure out their classpath, and the location of java binary on the system, but that's doable.
I think you can even be notified when they complete via Process.waitFor().
If you look at the
ant
source code, whenfork
istrue
, then it just wraps anExecute
task and eventually, the code that gets called isDownloading and having a look at the source code for
org.apache.tools.ant.taskdefs.Java
andorg.apache.tools.ant.taskdefs.Execute
will give you some great pointers in finding the location of the executable to run in a platform independent way, etc.I think you can directly use the Ant API...Ant can be directly used in a Java class. The Javadoc is available in their binary distribution.