> If I call setPriority in the constructor of a class that extends Thread
> isn't that going to set the priority of the main thread, since the new
> thread has not started?
>
> I can't find this in the javadocs.
setPriority isn't static
> If I call setPriority in the constructor of a class that extends Thread
> isn't that going to set the priority of the main thread, since the new
> thread has not started?
>
> I can't find this in the javadocs.
I can get a list of all existing threads. I can get their names, their
priorities,
if they are daemon threads or not etc.
To change a threads priority you have to specify which one. I don't see how
it matters if the thread has been started or not.
> If I call setPriority in the constructor of a class that extends Thread
> isn't that going to set the priority of the main thread, since the new
> thread has not started?
>
> I can't find this in the javadocs.
setPriority only affects the priority of the Thread instance on which
the method was called. It does not change the priority of the thread
that is executing the setPriority method, unless of course, the
executing thread is the same thread as the Thread instance on which the
method was called.
It doesn't matter if the Thread instance is "new" (i.e. just created, or
being created) or if the Thread instance is already running.
The following class shows your example case:
public class MyThread extends Thread {
public MyThread(int prio, Runnable target) {
super(target); // invoke constructor of parent
this.setPriority(prio); // change priority *in constructor*
}
private static void print(String msg, Thread t) {
System.out.print(msg);
System.out.print("\t prio=");
System.out.print(t.getPriority());
System.out.print("\t alive=");
System.out.print(t.isAlive());
System.out.println();
}
public static void main(String[] args) throws Exception {
final Thread mainThread = Thread.currentThread();
final MyThread myThread = new MyThread(Thread.MIN_PRIORITY,
new Runnable() {
public void run() {
print("Running\t main thread", mainThread);
print("Running\t my thread", Thread.currentThread());
}
});
print("Before\t main thread", mainThread);
print("Before\t my thread", myThread);
myThread.start(); // starts myThread
myThread.join(); // wait until myTread ends
print("After\t main thread", mainThread);
print("After\t my thread", myThread);
}
}

Signature
Regards,
Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \