Setting thread priorities

I'm using a ThreadPoolExecutor to manage my threads.

I want to change the priorities of some of the threads I'm running.

Because I'm using the above ExecutorService, I don't have references to the threads for each Runnable I'm running.

How can I change the priority of any of these Threads? Should I have an 'if' statement in each run() that, when activated, changes the priority of Thread.currentThread() ? That way the currentThread() would be guaranteed to be the one for the Runnable changing its priority, correct?

Any advice would be much appreciated.

[595 byte] By [KomodoDavea] at [2007-11-26 16:50:07]
# 1
If priority logic is really external to those Runnables You can pass them what it should be set to and set it every time on start without if.
_Dima_a at 2007-7-8 23:17:43 > top of Java-index,Core,Core APIs...
# 2
Sadly I need to oscillate the thread priorities according to results of calculations made during their running, so the initial priority isn't of great import.
KomodoDavea at 2007-7-8 23:17:43 > top of Java-index,Core,Core APIs...
# 3

You can set the initial priority by installing your own ThreadFactory.

However, if you need to dynamically change priority then you have no choice but to use Thread.currentThread().setPriority or else register active threads in some other way.

That said, priorities in Java are advisory - use them with care as they may not do what you want, or what you think they should, and the behaviour is totally platform and release dependent.

davidholmesa at 2007-7-8 23:17:43 > top of Java-index,Core,Core APIs...
# 4
Thank you David, that was very informative.
KomodoDavea at 2007-7-8 23:17:43 > top of Java-index,Core,Core APIs...