Thread doubt
posted 18 years ago
The result I got is as follows:
Pr of t1 = 5,Pr of t2 = 5,Pr of t3 = 5
Pr of t1 = 3,Pr of t2 = 6,Pr of t3 = 7
inside no args run
Run by one
�.
Run by one
Inside if block
inside no args run
Run by three
�.
Run by three
inside no args run
Run by two
�.
Run by two
Final run by main
Though t3 has max priority, t1 is run first.
value for NORM_PRORITY is 5, but I haven't given any Thread a priority of 5. Then how can the if loop execute?
Can anybody pls explain
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The result I got is as follows:
Pr of t1 = 5,Pr of t2 = 5,Pr of t3 = 5
Pr of t1 = 3,Pr of t2 = 6,Pr of t3 = 7
inside no args run
Run by one
�.
Run by one
Inside if block
inside no args run
Run by three
�.
Run by three
inside no args run
Run by two
�.
Run by two
Final run by main
Though t3 has max priority, t1 is run first.
value for NORM_PRORITY is 5, but I haven't given any Thread a priority of 5. Then how can the if loop execute?
Can anybody pls explain
posted 18 years ago
You are checking on the currentThread which is the "main Thread" which has a default priority of NORM_PRIORITY
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I haven't given any Thread a priority of 5. Then how can the if loop execute?
if(Thread.currentThread().getPriority() == Thread.NORM_PRIORITY){
You are checking on the currentThread which is the "main Thread" which has a default priority of NORM_PRIORITY
ram shah
Greenhorn
Posts: 28
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thank for your comments Ahmed...but, I have few more doubts
(1) how thread "one" is executing before thread "three" when priority of thread "three" is greatre than priority of thread "one".
(2) If I set the priorities as below,
t1.setPriority(9)
t2.setPriority(5)
t3.setPriority(5)
How can I modify the if statement so that if the priority of the thread is 5, it yields to the other thread with same priority.
(1) how thread "one" is executing before thread "three" when priority of thread "three" is greatre than priority of thread "one".
(2) If I set the priorities as below,
t1.setPriority(9)
t2.setPriority(5)
t3.setPriority(5)
How can I modify the if statement so that if the priority of the thread is 5, it yields to the other thread with same priority.
posted 18 years ago
Threads actually takes time to start. I can't tell without running your code, but I would say thread one is running because thread three hasn't started yet.
The way you coded it, only the main thread makes the check. You have to code it so that the threads that you want to check and yield, actually does the check and yield.
Henry
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
(1) how thread "one" is executing before thread "three" when priority of thread "three" is greatre than priority of thread "one".
Threads actually takes time to start. I can't tell without running your code, but I would say thread one is running because thread three hasn't started yet.
How can I modify the if statement so that if the priority of the thread is 5, it yields to the other thread with same priority.
The way you coded it, only the main thread makes the check. You have to code it so that the threads that you want to check and yield, actually does the check and yield.
Henry
| What a stench! Central nervous system shutting down. Save yourself tiny ad! Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











