/** * Perform the task once and notify the manager. */ public void run() { boolean execute = false; try { // System.out.println("Executing: "+this); execute = executable.execute(); } catch(RuntimeException e) { e.printStackTrace(); } synchronized(LoadManagingExecutionService.this) { if(execute) { LoadManagingExecutionService.this.execute(executable, priority); } LoadManagingExecutionService.this.taskPerformed(this); } }
public static void main(String[] args) { double PRIORITY = 0.1; LoadManagingExecutionService service = new LoadManagingExecutionService( ThreadPoolFactory.createThreadPool()); service.execute(new TestExecutable(), PRIORITY); service.execute(new TestExecutable(), PRIORITY); service.execute(new TestExecutable(), PRIORITY); service.execute(new TestExecutable(), PRIORITY+0.3); service.execute(new TestExecutable(), PRIORITY+0.3); service.execute(new TestExecutable(), PRIORITY+0.3); service.execute(new TestExecutable(), PRIORITY+0.8); service.execute(new TestExecutable(), PRIORITY+0.8); }