
There seems to be a problem using the timer task inside ANT v1.6 compliant targets.
Watch out for an updated version of the timer task which will be issued soon.
Extend Ant to measure amount of time elapsed to complete a build task.
The task now supports the high resolution timer (accessed by nanoTime
)
introduced by Java 1.5.
If present it will be used automatically otherwise the classical currentTimeMillis
will be used.
Note: The task will no longer compile using a JDK prior to version 1.5.
If you intend to run it under JRE 1.4 or earlier download the JAR archive.
- Download the JAR archive
- Add the JAR archive to Ant's classpath
- Add to following line to your Ant buildfile to create the include task
<taskdef name="timer" classname="de.jeckle.AntExtension.Timer"/>
- Installation finished!
Now you can define your own timer tasks.
- Define a new Ant task (e.g. named timer).
- Use the new task whereas the
verbose
attribute switches the verbose mode on if it contains the value true
.
Additionally, the timer task can be named by the name
attribute. - Embrace all tasks or sequences of tasks whose execution time should be measured by
timer
tasks.
 | Attribute | Description | Required |
---|
 | verbose | Turns verbose mode on if it contains the value true | No | name | Names the timer task | No |
|
<target name="test">
<timer verbose="true">
<echo>test1</echo>
</timer>
<timer name="timer2">
<echo>test2</echo>
<timer name="timer3" verbose="true">
<echo>test3</echo>
</timer>
<echo>test4</echo>
</timer>
</target>
Buildfile: build.xml
test:
[timer] System reports java version 1.5.0-beta
[timer] Using high resolution timer
[timer] started [echo] test1
[timer] elapsed time: 0 ms
[echo] test2
[timer] named timer3 started
[echo] test3
[timer] elapsed time for executing task named timer3: 2 minute(s) 7 second(s) 762 millisecond(s) 818327 nannosecond(s)
[echo] test4
[timer] elapsed time for executing task named timer2: 1 minute(s) 9 second(s) 235 millisecond(s) 593192 nannosecond(s)
BUILD SUCCESSFUL
Total time: 1 second
Download this example code
The implementation is released unter the Lesser
GNU Public License.
- Java J2SE v1.4+
- Ant v1.6 (2004-01-10)

Service provided by Mario Jeckle
Generated: 2004-06-11T07:11:41+01:00
Feedback
SiteMap
This page's original location: http://www.jeckle.de/freeStuff/AntTimerTask/index.html
RDF description for this page