aspose file tools*
The moose likes Java in General and the fly likes Thread priority Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread priority" Watch "Thread priority" New topic
Author

Thread priority

sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
Posts: 9
I am trying a practice code on thread priorities and and the user should enter the priority and i have tried the code .is it correct or not?it not can suggest the corrections
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

The name of a thread does not have anything to do with its priority. Your program is trying to compare the name of the thread to Thread.MIN_PRIORITY (line 5) and Thread.MAX_PRIORITY (line 10), which is strange. Why did you write it that way?

Also, it's really strange that the thread would do different things (multiply or add two numbers) depending on its priority. You'd normally not write a program that has a completely different function if the priority of a thread is different.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
Posts: 9
then what shall i do in that place i have tried to assign thread to current thread also unable to get it!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

What exactly do you want your program to do? Without knowing exactly what your intention is, it's hard to give you hints to get you on your way.
sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
Posts: 9
in the program when the user enters number between 1-10 i.e priority.if the priority matches minimum priority it should perform product of two numbers and display and if matches maxmum priority it should perform addition operation.these have to be in run().
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
sukruthi dandasi wrote:in the program when the user enters number between 1-10 i.e priority.if the priority matches minimum priority it should perform product of two numbers and display and if matches maxmum priority it should perform addition operation.these have to be in run().

At the moment all you are doing is creating a Thread object and setting its priority. You never actually start the thread, nor do you tell the Thread that when it starts it should run the run method in your class.
You might want to read this tutorial and find out how to do these basic things before you worry about the details of exactly what your method does. See if you can just get a message to print out from your classes run method first.

Joanne
sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
Posts: 9
i forgot to type in the program t1.start(); after setting the priority for p which was given as input for the user
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
sukruthi dandasi wrote:i forgot to type in the program t1.start(); after setting the priority for p which was given as input for the user

Okay. So is everything working now or do you still have problems ?
sukruthi dandasi
Greenhorn

Joined: Jan 12, 2013
Posts: 9
no its not working in run() .i am just able to enter input and i know that if the priority is set by setPriority() and in order to get that supposed to use getPriority().where should i implement that?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
sukruthi dandasi wrote:no its not working in run() .i am just able to enter input and i know that if the priority is set by setPriority() and in order to get that supposed to use getPriority().where should i implement that?

In your run method where you currently call getName would probably be a good place to try.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Please repost the code as it currently stands. My guess is that you did not notice this piece of advice:
Joanne Neal wrote:You never actually start the thread, nor do you tell the Thread that when it starts it should run the run method in your class.


Steve
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8251
    
  23

sukruthi dandasi wrote:I am trying a practice code on thread priorities...

Well, quite apart from the fact that you're using them for something that has nothing to do with what they were designed for, can I ask why?

I have to admit never having used them myself, but if they're anything like process ('nice') priorities in Unix, the basic rule of thumb is: Don't change them unless you really know what you're doing.

ie: It's something that's best left to experts.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread priority