@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(_id).append(" ").append(getStatusString()).append(" "); sb.append(_runnable.toString()); return sb.toString(); }
@Override public int add(Queable runnable) { synchronized (_lock) { int id = _nextId++; runnable.queued(id); if (_maxActiveJobs <= 0) { LOGGER.warn( "A task was added to queue '{}', however the queue is not configured to execute any tasks.", _name); } SJob job = new SJob(runnable, id); _jobs.put(id, job); _queue.add(job); _lock.notifyAll(); return id; } }
@Override public void run() { synchronized (this) { _startTime = System.currentTimeMillis(); } try { _cdc.restore(); NDC.push("job=" + _id); _runnable.run(); } finally { CDC.clear(); synchronized (this) { _status = REMOVED; } synchronized (_lock) { _jobs.remove(_id); _activeJobs--; _lock.notifyAll(); } } }
public synchronized void kill() { _runnable.kill(); }