• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to call getPriority() on the main thread

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may also be of interest: https://coderanch.com/how-to/java/ThreadLister
 
reply
    Bookmark Topic Watch Topic
  • New Topic