void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }