This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread priority

 
sukruthi dandasi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sukruthi dandasi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sukruthi dandasi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic