Guy Guy - 1 year ago 95
Java Question

Setting priority to Java's threads

I have a program that runs in a few threads. The main thread shares an object with the other threads and in the main I have a call to:

do stuff

I have a suspicion that the main thread is starved and isn't getting access to
. How do I raise the priority of the main thread or is it already higher than the other threads by default?

Answer Source

You have a setPriority() method in the Thread class.

Check this javadoc.

Setting thread priority to maximum:

public static void main(String args[]) {
    // Your main code.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download