About Question enthuware.ocpjp.v7.2.1396 :

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

Moderator: admin

Post Reply
sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

About Question enthuware.ocpjp.v7.2.1396 :

Post by sinapse »

If the control goes to the TestClass thread which enter in an infinite lopp, we can't be sure that the main thread will be able to print "Main Returns" can't we ?

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

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

Post by admin »

"Main returns" is being printed from the main thread, which is different from the thread created by the line new TestClass().start();

So it will be printed no matter what the other thread does.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

One thread at time can be running right ?
So if the TestClass thread is running for ever how can we be sure that the main thread will return ?

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

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

Post by admin »

There are many possibilities. One is OS can run both the threads on different cores. Second is OS may use time slicing to avoid thread starvation.

Letting multiple threads run simultaneously is the goal of multithreading after all.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

Ok I got you ! But we can't be sure that starvation will not arise right ?

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

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

Post by admin »

Yes, you can't sure of that.
If you like our products and services, please help us by posting your review here.

sinapse
Posts: 27
Joined: Sat Aug 31, 2013 5:38 pm
Contact:

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

Post by sinapse »

Which means that the main thread won't always return right ?

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

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

Post by admin »

Well, I think you have a point but it is a stretch. I would rather make the assumption that it will print it.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

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

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

Post by krohani »

I agree with the original poster's assertion that there is a chance (albeit a very, very slight chance) that the JVM gives ALL cycles to the TestClass thread and none to the main thread and as a result the main thread never completes.

Given that miniscule chance I answer the question in that manner thinking that the creators of the question were testing the principle that there is never any guarantee as to which threads get scheduled by the JVM.

In my opinion the creators of this question should review either a) the whole question b) the answer choices or c)put a more descriptive question with a specific scenario.

kwetal
Posts: 5
Joined: Thu Apr 03, 2014 3:50 am
Contact:

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

Post by kwetal »

I agree with the topic starter sinapse: the JVM might run on a platform that does not support preemptive scheduling (e.g., old Windows 3.1), so the infinite loop may get control before the main thread gets the chance to print "Main returns" and because the other thread never does a yield(), the main thread never will acquire control again.

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

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

Post by admin »

Well, if there is no preemptive scheduling, how will the other thread get to run before the main thread is complete?
If you like our products and services, please help us by posting your review here.

kwetal
Posts: 5
Joined: Thu Apr 03, 2014 3:50 am
Contact:

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

Post by kwetal »

Any call from the user program to a system or kernel routine gives the system the opportunity to intercept the current thread and yield to another thread.

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

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

Post by admin »

And I will be repeating what I said earlier in this thread. This argument is really a stretch and I do not think it is relevant for the purpose of the exam.
Here is an interesting discussion that I found: https://stackoverflow.com/questions/145 ... preemptive

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 45 guests