About Question enthuware.ocpjp.v7.2.1549 :

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

Moderator: admin

Post Reply
Crashtest
Posts: 18
Joined: Fri May 31, 2013 1:18 pm
Contact:

About Question enthuware.ocpjp.v7.2.1549 :

Post by Crashtest »

I wanted to answer "None of these" because I think it could be possible that a.interrupt(); is called before a.start() is scheduled by the OS to actually run (in rare occasion I guess).

Also, the answer "none of these" makes not much sense if you have to select two options... So this ruled it out for me straight away.

pfilaretov
Posts: 35
Joined: Mon Jul 28, 2014 2:05 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1549 :

Post by pfilaretov »

I agree with the previous post.

Also in this code

Code: Select all

public void run()    {       
   System.out.println("Starting loop");       
   while(true){}; //1       
   System.out.println("Ending loop");    
}
actually unreachable statement is semicolon (and not the println()), notice that it is NOT in the body of the while loop.

monseigneur
Posts: 6
Joined: Sun Aug 09, 2015 6:55 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1549 :

Post by monseigneur »

could you please clarify

Code: Select all

class A extends Thread {    
public void run()    {     
System.out.println("Starting loop");  
while(true){}; //1      
System.out.println("Ending loop");    
} } 

public class TestClass {    
public static void main(String args[]) throws Exception    {      
A a = new A();       
a.start();         
 //1
Thread.sleep(1000);       //2
a.interrupt();    //3
} }
what i reckon:
at //1 we have two threads running - main and a
by calling Thread.sleep(1000) at //2 we put to sleep one of them, the current thread, and we don't know which one is it exactly (do we?)
so, if, say, a is put to sleep and main thread calls a.interrupt() meanwhile at //3, shouldn't a throw an InterruptedException?

what am i missing here?

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

Re: About Question enthuware.ocpjp.v7.2.1549 :

Post by admin »

monseigneur wrote: what i reckon:
at //1 we have two threads running - main and a
by calling Thread.sleep(1000) at //2 we put to sleep one of them, the current thread, and we don't know which one is it exactly (do we?)
Of course we do. Sleep is being called from the main method so the thread executing the main method is the one that will go to sleep.

monseigneur
Posts: 6
Joined: Sun Aug 09, 2015 6:55 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1549 :

Post by monseigneur »

great, thank you

krohani
Posts: 31
Joined: Tue Oct 06, 2015 1:57 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1549 :

Post by krohani »

Good curve ball question. I was concentrating so hard on Thread concepts trying to figure out what I am missing here that I didn't even bother to pay attention to the unreachable statement! Missed the question however!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests