FileDocCategorySizeDatePackage
Sleep.javaAPI DocApache Ant 1.704764Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

Sleep

public class Sleep extends org.apache.tools.ant.Task
Sleep, or pause, for a period of time. A task for sleeping a short period of time, useful when a build or deployment process requires an interval between tasks.

A negative value can be supplied to any of attributes provided the total sleep time is positive, pending fundamental changes in physics and JVM execution times

Note that sleep times are always hints to be interpreted 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.

since
Ant 1.4
ant.task
category="utility"

Fields Summary
private boolean
failOnError
failure flag
private int
seconds
sleep seconds
private int
hours
sleep hours
private int
minutes
sleep minutes
private int
milliseconds
sleep milliseconds
Constructors Summary
public Sleep()
Creates new instance




            
      
    
Methods Summary
public voiddoSleep(long millis)
sleep for a period of time

param
millis time to sleep

        try {
            Thread.sleep(millis);
        } catch (InterruptedException ie) {
            // Ignore Exception
        }
    
public voidexecute()
Executes this build task. Throws org.apache.tools.ant.BuildException if there is an error during task execution.

exception
BuildException Description of Exception

        try {
            validate();
            long sleepTime = getSleepTime();
            log("sleeping for " + sleepTime + " milliseconds",
                Project.MSG_VERBOSE);
            doSleep(sleepTime);
        } catch (Exception e) {
            if (failOnError) {
                throw new BuildException(e);
            } else {
                String text = e.toString();
                log(text, Project.MSG_ERR);
            }
        }
    
private longgetSleepTime()
return time to sleep

return
sleep time. if below 0 then there is an error

        return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000
            + milliseconds;
    
public voidsetFailOnError(boolean failOnError)
flag controlling whether to break the build on an error.

param
failOnError The new FailOnError value

        this.failOnError = failOnError;
    
public voidsetHours(int hours)
hours to add to the sleep time.

param
hours The new Hours value

        this.hours = hours;
    
public voidsetMilliseconds(int milliseconds)
milliseconds to add to the sleep time

param
milliseconds The new Milliseconds value

        this.milliseconds = milliseconds;
    
public voidsetMinutes(int minutes)
minutes to add to the sleep time

param
minutes The new Minutes value

        this.minutes = minutes;
    
public voidsetSeconds(int seconds)
seconds to add to the sleep time

param
seconds The new Seconds value

        this.seconds = seconds;
    
public voidvalidate()
verify parameters

throws
BuildException if something is invalid

        if (getSleepTime() < 0) {
            throw new BuildException("Negative sleep periods are not "
                                     + "supported");
        }