I am sure that one of these exists and was posted before, but couldn't find it when I needed to wait a while for something to sort itself out during deployment
So here is a task to sleep for a while, where "a while" is defined as any
number of milliseconds greater than or equal to zero. Some higher level
times are given, seconds being the most useful. sub second delays are very
subject to OS and JVM whims to be recommended. You can send negative numbers
too, but the total delay must be in the future rather than the past, pending
some fundamental enhancements in speculative instruction execution :-)
<sleep />
<sleep milliseconds="10"/>
<sleep seconds="2"/>
<sleep hours="1" minutes="-59" seconds="-58"/>
<sleep hours="1" />
No unusual dependencies on j2ee, jaxp or xml parsers, no funny behaviour
related to remote web servers and an nice simple test harness which may
break if some platforms do return earlier than multi-second sleep requests
ask for, or just have a broken clock.
[I would have include the patch for default properties, but changing doesnt
seem to work for me. I am doing something wrong]
-Steve
<project name="sleeptest" default="all" >
<target name="init">
<taskdef name="sleep"
classname="org.apache.tools.ant.taskdefs.optional.Sleep"/>
</target>
<target name="test1" depends="init">
<sleep />
</target>
<target name="test2" depends="init">
<sleep milliseconds="10"/>
</target>
<target name="test3" depends="init">
<sleep seconds="2"/>
</target>
<target name="test4" depends="init">
<sleep hours="1" minutes="-59" seconds="-58"/>
</target>
<target name="test5" depends="init">
<sleep minutes="-59" seconds="-58"/>
</target>
<target name="test6" depends="init">
<sleep minutes="-59" seconds="-58" failonerror="no"/>
</target>
<target name="all"
depends="test1,test2,test3,test4,test5" />
</project>
SleepTest.java
Description: Binary data
Sleep.java
Description: Binary data
Sleep
Description
A task for sleeping a short period of time, useful when a build or deployment process requires an interval between tasks.
Parameters
| Attribute | Description | Required |
| hours | hours to to add to the sleep time | No |
| minutes | minutes to add to the sleep time | No |
| seconds | seconds to add to the sleep time | No |
| milliseconds | milliseconds to add to the sleep time | No |
| failonerror | flag controlling whether to break the build on an error. | No |
The sleep time is the sum of specified values, hours, minutes seconds and milliseconds. A negative value can be supplied to any of them provided the total sleep time is positive
Note that sleep times are always hints to be interpred by the OS how it feels - small times may either be ignored or rounded up to a minimum timeslice. Note also that the system clocks often have a fairly low granularity too, which complicates measuring how long a sleep actually took.
Examples
<sleep milliseconds="10"/>Sleep for about 10 mS.
<sleep seconds="2"/>Sleep for about 2 seconds.
<sleep minutes="-59" seconds="-58"/>
Sleep for -one hour less 59:58, or two seconds again
<sleep />Sleep for no time at all. This may yield the CPU time to another thread or process.
Copyright © 2000,2001 Apache Software Foundation. All rights Reserved.
optionaltasklist.diff
Description: Binary data
