aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Question from Dan's mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Question from Dan Watch "Thread Question from Dan New topic
Author

Thread Question from Dan's mock exam

Reshma Shanbhag
Ranch Hand

Joined: Sep 17, 2002
Posts: 202
Hi all,
Question 2
Which of the following are true?
a. A program will terminate only when all daemon threads stop running.
b. A program will terminate only when all user threads stop running.
c. A daemon thread always runs at Thread.MIN_PRIORITY.
d. A thread inherits its daemon status from the thread that created it.
e. The daemon status of a thread can be changed at any time using the Thread.setDaemon method.
f. The Thread.setDaemon method accepts one of two argument values defined by the constants Thread.DAEMON and Thread.USER.
g. None of the above.
Answer is (b) & (d)
Its right that a thread created from daemon thread is always a daemon thread. The option (d) cannot be generalized to create daemon threads, as a thread obtained from non-daemon thread can be made to work as daemon thread using setDaemon(true). So how can we consider the option (d) as fully correct.
Plz help me with this, i am always confused with such multiple choice questions..
Thanks
reshma


SCJP 1.4, SCWCD 1.4
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
concerning multiple choice questions, all i can say is, i am thankful they are going to give me options of how many answers to provide in the real exam!
i think the key to answer (d) is in the wording - specifically the first word... "A"; not "All"".
d. A thread inherits its daemon status from the thread that created it.
as you say, not all daemon threads are created from daemon threads. i guess it would have been obviously INcorrect if it was worded such as-
d. All daemon threads inherit their daemon status from the daemon threads that created them.
but as it stands, it can be seen as correct.


giddee up
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
I don't see any ambiguity in d option.
It is right that when a thread is created from daemon thread you get deamon status. If you create a thread from user thread then you get user thread.
It is not saying that it is the final status and you can't change it. No. You can chage the thread from daemon to user or vice versa before starting the thread.
It is only talking about what you get immidiately after creation from parent thread before executing next line. May be in the very next line you change the thread to user. But it is a different story.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
As Sarma stated above, each new thread inherits the daemon status of the thread that created the new thread. Before the new thread is started, the daemon status can be changed using the setDaemon method.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Question from Dan's mock exam