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); }
/** * Set the stepmode. * @param stepmode True for stepmode. */ public void setStepmode(boolean stepmode) { this.stepmode = stepmode; if(!stepmode) executor.execute(); }
/** * Execute a task in its own thread. * @param task The task to execute. */ public synchronized void execute(Runnable task) { // if(!isValid()) // throw new RuntimeException("Service invalid: "+this); threadpool.execute(task); }
public void timeEventOccurred(long currenttime) { ret.setExceptionIfUndone(new TimeoutException()); } });
/** * Test if the thread pool is running. */ public boolean isRunning() { return threadpool.isRunning(); }
/** * Called, when the clock is no longer used. */ public void dispose() { executor.shutdown(); // Wake up timer thread, if currently waiting. synchronized(this) { this.notify(); } // notificator.shutdown(null); }
/** * Shutdown the service. * @param listener The listener. */ public synchronized IFuture<Void> shutdownService() { threadpool.dispose(); return super.shutdownService(); }
/** * Add a finished listener. */ public void addFinishListener(IChangeListener<Void> listener) { threadpool.addFinishListener(listener); } }
/** * The task for a given thread. */ protected synchronized Runnable getTask(Thread thread) { Runnable ret = null; if(thread instanceof ServiceThread) { ret = ((ServiceThread)thread).getTask(); } return ret; }
/** * Create some pool. * @param num The number of pool. */ protected synchronized void addThreads(int num) { for(int i=0; i<num; i++) { addThread(); } }
/** * Main for testing. */ public static void main(String[] args) { new ThreadTest(); }
/** * The code to be run. * @return True, when execution should continue. */ protected boolean code() { return executable.execute(); }
/** * Execute a task in its own thread. * @param task The task to execute. */ public synchronized void execute(Runnable task) { // if(!isValid()) // throw new RuntimeException("Service invalid: "+this); threadpool.execute(task); }
public void resultAvailable(Void result) { if(!unblocked[0]) { unblock(monitor, new TimeoutException(Future.DEBUG ? "" : "Use PlatformConfiguration.setDebugFutures(true) for timeout cause.", ex)); } }
/** * Execute a step. */ public void doStep() { dostep = true; if(stepmode) executor.execute(); }
/** * Test if the thread pool is running. */ public boolean isRunning() { return threadpool.isRunning(); } }
/** * Execute a task in its own thread. * @param task The task to execute. */ public synchronized void execute(Runnable task) { // if(!isValid()) // throw new RuntimeException("Service invalid: "+this); threadpool.execute(task); }
public IFuture<Void> execute(IInternalAccess ia) { // if(rescom.equals(getResumeCommand())) { setException(new TimeoutException()); RPlan.executePlan(RPlan.this, ia, rescom); } return IFuture.DONE; } });
/** * Set the stepmode. * @param stepmode True for stepmode. */ public void setStepmode(boolean stepmode) { this.stepmode = stepmode; if(!stepmode) executor.execute(); }
/** * Execute a step. */ public void doStep() { dostep = true; if(stepmode) executor.execute(); }