Page 1 of 1
About Question com.enthuware.ets.scjp.v6.2.553 :
Posted: Sat Feb 25, 2012 4:03 pm
by MC20147
I beleive there are no daemon thread questions on the new Oracle exam.
Thanks,
Mark
Re: About Question com.enthuware.ets.scjp.v6.2.553 :
Posted: Sat Feb 25, 2012 11:51 pm
by admin
Yes, theoretically they have been removed from the objectives but some candidates have reported seeing them on the exam. So we have kept a couple (I think there are only 2 questions) about it in the question bank, just to make sure there are no surprises.
HTH,
Paul.
Re: About Question com.enthuware.ets.scjp.v6.2.553 :
Posted: Sat Jan 12, 2013 4:47 pm
by xpst
I guess these two options (marked as correct) are contradict each other:
A program ends when all non-daemon threads end.
A program ends when all threads end.
Second option sounds like
A program ends when all threads (non-daemon and daemon) end.
And regarding this explanation
You can stop any thread.
Could you please show me how can I stop
for sure any thread (non-daemon and daemon)?
Re: About Question com.enthuware.ets.scjp.v6.2.553 :
Posted: Sat Jan 12, 2013 5:12 pm
by admin
A program ends when all non-daemon threads end. All threads includes daemon and non daemon threads. Therefore, if all threads end, the program will end. But I see what you are saying. It may also imply that a program does not end until all threads end, which is not true.
The option "You can stop any threads" refers to any daemon or non-daemon thread and that there is no restriction as to which thread you can stop and which you cannot. Of course, if a thread is waiting on a socket connection, you may not be able to "stop" it but that is not an issue with thread but the socket. Other than that, the following code shows how you can stop a thread for sure:
Code: Select all
public class Test {
static Thread t;
public static void main(String[] args) throws Exception{
t = new Thread(){
public void run(){
for(;;){
System.out.println("in thread");
}
}
};
t.start();
Thread.sleep(1000);
t.stop();
}
}
}
Note that stop method is deprecated but nonetheless it is available.
HTH,
Paul.