This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to call getPriority() on the main thread  RSS feed

 
Bud Tippins
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code. I am trying to obtain the value for the main thread's priority level.

On line # 22 I'm getting an error (from NetBeans) saying that "cannot find symbol - symbol: variable main"

What do I need to change to get main's priority level to be printed?

Any help greatly appreciated. Thank you.


 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because you call it the "main" thread, that doesn't mean that Java has to provide an undeclared variable named "main" to refer to that thread. And it doesn't.

But what you call the "main" thread is the current Thread at that point in the code. At least that's what I guess you meant... am I right? The Thread which executes that line of code? If so, check out the API documentation for the Thread class and find the method for getting the current Thread.
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main thread does not have a magical name called "main". You must first get a new reference to it. Since you are on the main thread itself that's easy: call Thread.currentThread().
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bud Tippins wrote:

Yes, it seems obvious this line is executed in the "main" thread, but this type of thing makes me nervous. In more complex situations (or when you copy and paste code), assumptions like these make debugging a nightmare. So once you have a reference to the current thread (maybe called "thisThread"), you might consider getting its actual name to be certain...

Just something to consider.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may also be of interest: http://www.coderanch.com/how-to/java/ThreadLister
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!