1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import org.apache.tools.ant.Task; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 25 39 public class Nice extends Task { 40 41 44 private Integer newPriority; 45 46 49 private String currentPriority; 50 51 52 53 57 public void execute() throws BuildException { 58 59 Thread self = Thread.currentThread(); 60 int priority = self.getPriority(); 61 if (currentPriority != null) { 62 String current = Integer.toString(priority); 63 getProject().setNewProperty(currentPriority, current); 64 } 65 if (newPriority != null && priority != newPriority.intValue()) { 67 try { 68 self.setPriority(newPriority.intValue()); 69 } catch (SecurityException e) { 70 log("Unable to set new priority -a security manager is in the way", 72 Project.MSG_WARN); 73 } catch (IllegalArgumentException iae) { 74 throw new BuildException("Priority out of range", iae); 75 } 76 } 77 } 78 79 84 public void setCurrentPriority(String currentPriority) { 85 this.currentPriority = currentPriority; 86 } 87 88 92 public void setNewPriority(int newPriority) { 93 if (newPriority < Thread.MIN_PRIORITY || newPriority > Thread.MAX_PRIORITY) { 94 throw new BuildException("The thread priority is out of the range 1-10"); 95 } 96 this.newPriority = new Integer (newPriority); 97 } 98 99 } 100
| Popular Tags
|