+6  A: 

Currently the only concrete implementations of the Executor interface are the ThreadPoolExecutor and the ScheduledThreadpoolExecutor

Instead of using the utility / factory class Executors, you should create an instance using a constructor.

You can pass a BlockingQueue to the constructors of the ThreadPoolExecutor.

One of the implementations of the BlockingQueue, the PriorityBlockingQueue lets you pass a Comparator to a constructor, that way enabling you to decide the order of execution.

davyM
+1 PriorityBlockingQueue is the way to go. You can implement a Comparator or make the tasks themselves Comparable.
Tim Bender
A: 

davyM has a good answer but I thought I'd also mention that the following method exists in Java:

Thread.setPriority(int newPriority)

This sets the internal Java thread scheduling priority for the thread. A thread can use Thread.currentThread() to set its own priority, or you can set the priority of a thread externally. According to the code, the default priority is 5, the minimum is 1, and the maximum is 10. A thread inherits the priority of the thread that created it.

This priority is only relevant for CPU intensive threads only -- in situations where you have a number of threads that are performing calculations and you want one to get larger time-slices from the scheduler. Obviously if a thread is blocking on IO, the priority is going help marginally. Also, I suspect that how this behaves on a multi-processor box is very OS dependent.

Here's a page that seems useful although they don't seem to take into account thread starvation: http://www.janeg.ca/scjp/threads/scheduling.html

Gray
This type of priority is different from what the OP is requesting. If you have a newSingleThreadedExecutor and alter the thread prirority using a ThreadFactory the OP will see the exact same results 100% of the time when submitting tasks. However if you use davyM's suggestion with a newSingleThreadedExecutor the OP will observe different (more accurate) execution sequences.
John V.