Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Related Problem

 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q12. If one does not assign a priority to a Thread object, it assumes a priority of ___ by default.
0
5
1
None of the above


This is the question from www.tipsmart.com , what will be the ans of this according to me , it should be 5 , but site is giving ans "None of the above" . I am confused why ??? Please help me out ...

Q10. State which of the following statements are True.
(1) Concurrent Java programs can exhibit deterministic behavior, by providing mechanisms for synchronizing.
(2) Threads have parent-child relationships.
(3) When the thread is created, it is not yet active


What will be the ans for this question also , site is saying that Threads don't have parent-child relationships. But I my view they have parent child relationship .
[ May 18, 2005: Message edited by: Rohan Kayan ]
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class ThreadPriority extends Thread{
public static void main(String[] args) {
ThreadPriority one = new ThreadPriority();
System.out.println(one);
System.out.println(one.getPriority());
System.out.println(one.currentThread().getName());
}
}

Output:

Thread[Thread-0,5,main]
5
main


Here "5" is the threads priority and "main" is Threads Name
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A thread's default priority is the priority of its parent thread (not necessary to be main whose priority is 5). Hence "none of the above"
 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reply for Vishnu
But if we set the priority of main thread as 10 and then I will create a thread with out any priority specified , the the default priority of the child thread will be 10 . Then how can we say that the default priority of thread is 5 ??
[ May 18, 2005: Message edited by: Rohan Kayan ]
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But if we set the priority of main thread as 10 and then I will create
a thread with out any priority specified , the the default priority of
the child thread will be 10 . Then how can we say that the default
priority of thread is 5 ??


The question says
If one does not assign a priority to a Thread object

as Nischal said a threads priority depends on its parent threads priority



Ans:
8
8
8
8
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But if we set the priority of main thread as 10 and then I will create
a thread with out any priority specified , the the default priority of
the child thread will be 10 . Then how can we say that the default
priority of thread is 5 ??


The question says
If one does not assign a priority to a Thread object

as Nischal said a threads priority depends on its parent threads priority



Ans:
8
8
8
8
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic