Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Thread.setPriority outside of run method

Reply
Thread Tools

Thread.setPriority outside of run method

 
 
grk@usa.net
Guest
Posts: n/a
 
      06-16-2005
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.

 
Reply With Quote
 
 
 
 
Vova Reznik
Guest
Posts: n/a
 
      06-16-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
 
Reply With Quote
 
 
 
 
Lucy
Guest
Posts: n/a
 
      06-16-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.


 
Reply With Quote
 
Roland
Guest
Posts: n/a
 
      06-16-2005
On 16-6-2005 20:01, (E-Mail Removed) wrote:

> 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);
}
}
--
Regards,

Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
outside type, outside function Krzysztof Poc C++ 1 02-07-2012 04:06 PM
Pix 506e w/5 static outside IPs - How to create a rule to allow ALL tcp/udp traffic from one outside IP to an internal IP (for an internal router/NAT with it's own subnet) kyoo Cisco 22 04-12-2008 03:37 PM
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
CallForward outside->inside->outside failed after one ring. Yogz Cisco 1 04-16-2007 03:58 PM
nat from outside to outside dt1649651@yahoo.com Cisco 1 08-21-2005 04:26 PM



Advertisments