Looks like there isn't really a way to do this directly. One approach would be to have each task set its priority for itself as it runs, using a simple decorator:
This would work well enough to set a
lower priority. However if you want to set a
higher priority, beware that the
thread won't acquire that higher priority until after it starts running (and completes the first three lines of the run() method). Which may be slightly unsatisfactory, but it's better than nothing.
Another approach would be to forget about priorities
while a job is executing, and instead focus on the priorities of tasks waiting to
start executing. You could use a PriorityBlockingQueue to manage a group of tasks waiting to start execution by a group of worker threads, e.g. from Executors.newFixedThreadPool(). Whenever the pool is available to add a new task (as evidenced by the execute() method not blocking), use the priority queue to determine
which task to add. This solution is also imperfect - it does nothing to affect the relative priorities of tasks
while they execute. Also you need to pick out a new task
before calling execute(), which may block - so what you get is the highest-priority task that was in the queue when you
first started waiting for an available thread. Not necessarily the highest-priority task later when the thread becomes available. So again it's not perfect, but better than nothing.
It's also possible to combine these two approaches, as well as to extend the wrapper idea to obtain the highest-priority task
currently available. Though additional complications may emerge, and it starts to be more like building your own thread pool rather than using existing libraries. Could be I'm missing some easier way to go about this...