/** * Creates a new worker queue with the specified thread name * @param threadName */ public WorkerQueue(String threadName) { m_queueThread = new Thread(createQueueLoop(), threadName); }
/** * Called by this class, this method checks if the queue is empty; * if it is, then waits, else returns the current job. * * @see #putJob * @return the executable * @throws InterruptedException */ protected synchronized Executable getJob() throws InterruptedException { // Preconditions if (m_queueThread == null || !m_queueThread.isAlive()) { throw new IllegalStateException(); } return getJobImpl(); }
/** * Called by a thread that is not the WorkerQueue thread, this method * queues the job and, if necessary, wakes up this worker queue that is * waiting in {@link #getJob}. * @param job */ public synchronized void putJob(Executable job) { // Preconditions if (m_queueThread == null || !m_queueThread.isAlive()) { throw new IllegalStateException("Can't put job, thread is not alive or not present"); } if (isInterrupted()) { throw new IllegalStateException("Can't put job, thread was interrupted"); } putJobImpl(job); }
if (isInterrupted()) getJob().execute(); clear();
protected void clear() { super.clear(); synchronized (this) { m_heap.clear(); } }
/** * Creates a new worker queue with the specified thread name * and daemon mode flag * @param threadName * @param isDaemon */ public WorkerQueue(String threadName, boolean isDaemon) { m_queueThread = new Thread(createQueueLoop(), threadName); m_queueThread.setDaemon(isDaemon); }