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

Nice

public class Nice extends org.apache.tools.ant.Task
A task to provide "nice-ness" to the current thread, and/or to query the current value. Examples:
 <nice currentPriority="current.value" >

Set currentPriority to the current priority

 <nice newPriority="10" >

Raise the priority of the build process (But not forked programs)

 <nice currentPriority="old" newPriority="3" >

Lower the priority of the build process (But not forked programs), and save the old value to the property old.

ant.task
name="nice" category="control"

Fields Summary
private Integer
newPriority
the new priority
private String
currentPriority
the current priority
Constructors Summary
Methods Summary
public voidexecute()
Execute the task

exception
BuildException if something goes wrong with the build


        Thread self = Thread.currentThread();
        int priority = self.getPriority();
        if (currentPriority != null) {
            String current = Integer.toString(priority);
            getProject().setNewProperty(currentPriority, current);
        }
        //if there is a new priority, and it is different, change it
        if (newPriority != null && priority != newPriority.intValue()) {
            try {
                self.setPriority(newPriority.intValue());
            } catch (SecurityException e) {
                //catch permissions denial and keep going
                log("Unable to set new priority -a security manager is in the way",
                        Project.MSG_WARN);
            } catch (IllegalArgumentException iae) {
                throw new BuildException("Priority out of range", iae);
            }
        }
    
public voidsetCurrentPriority(java.lang.String currentPriority)
The name of a property to set to the value of the current thread priority. Optional

param
currentPriority the property name.

        this.currentPriority = currentPriority;
    
public voidsetNewPriority(int newPriority)
the new priority, in the range 1-10.

param
newPriority the new priority value.

        if (newPriority < Thread.MIN_PRIORITY || newPriority > Thread.MAX_PRIORITY) {
            throw new BuildException("The thread priority is out of the range 1-10");
        }
        this.newPriority = new Integer(newPriority);