简体   繁体   中英

Slow web requests in java when using Ant

I'm working on a school project that uses Apache Ant . In my project I am performing web requests.

Check out a specific target in my build.xml file:

<target name="daemon" depends="build.all">
    <java 
        classpathref="run.path.id"
        classname="xxx.xxx.Daemon"
        fork="false">
    </java>
</target>

If I run this target, all web requests take approximately 30 seconds ( each ) to complete. If I change the fork attribute to:

<target name="daemon" depends="build.all">
    <java 
        classpathref="run.path.id"
        classname="xxx.xxx.Daemon"
        fork="true">
    </java>
</target>

the requests complete almost immediately (less than a second).


From https://ant.apache.org/manual/Tasks/java.html about the fork attribute:

if enabled triggers the class execution in another VM (disabled by default)

Why does this have such a tremendous impact on the performance of web requests?


UPDATE:

This is only an issue on Windows. I tested 2 separate machines running Windows. Both exhibited this behavior. I then spun up one VM (running Ubuntu) on each and the daemon target ran perfectly regardless of the value of the fork attribute.

If you run a java command this will create a process of it's own which will run in a separate thread within the same JVM. So while the process is created from the thread that runs Ant , it does not run immeadiatly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM