About Question com.enthuware.ets.scjp.v6.2.553 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
MC20147
Posts: 9
Joined: Sat Feb 25, 2012 3:51 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.553 :

Post by MC20147 »

I beleive there are no daemon thread questions on the new Oracle exam.

Thanks,

Mark

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.553 :

Post 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.
If you like our products and services, please help us by posting your review here.

xpst
Posts: 2
Joined: Sun Jan 06, 2013 9:38 am
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.553 :

Post 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)?

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.553 :

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 215 guests