[concurrency-interest] LIFO queuing

Bjørn-Ove Heimsund bjornoh@mi.uib.no
Wed, 10 Dec 2003 14:55:29 +0100 (CET)


I've been using the precursor to the java.util.concurrent package, which
includes the FJTasks. Using these, I could fill up an FJTaskRunnerGroup
with FJTasks to keep all CPUs busy.

However, each FJTask might spawn new FJTasks, and the parent would have to
wait for the children threads to finish before it could resume. The method


would then block (cyclic dependency), as it's a FIFO type queue. As an
alternative, I checked if the running thread is an FJTaskRunner, and if
so, new tasks would be put in front of the queue (LIFO style). This
avoided all issues, and performance was excellent. The code snippet is:

 if ((Runnable) Thread.currentThread() instanceof FJTaskRunner) {
   FJTask task = new FJTask(thread);
   task.fork(); // LIFO insertion

Now, it is not clear to me how to do this in the upcomming
java.util.concurrent. How can I explicitly preempt a running thread in
favor of a given thread?

Bjørn-Ove Heimsund
Centre for Integrated Petroleum Research
University of Bergen, Norway

(+47) 555 84962