About Question enthuware.ocpjp.v7.2.1396 :
Moderator: admin
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1396 :
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 ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
"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.
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.
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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 ?
So if the TestClass thread is running for ever how can we be sure that the main thread will return ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
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.
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
Ok I got you ! But we can't be sure that starvation will not arise right ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
Yes, you can't sure of that.
If you like our products and services, please help us by posting your review here.
-
- Posts: 27
- Joined: Sat Aug 31, 2013 5:38 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
Which means that the main thread won't always return right ?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 31
- Joined: Tue Oct 06, 2015 1:57 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
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.
-
- Posts: 5
- Joined: Thu Apr 03, 2014 3:50 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
-
- Posts: 5
- Joined: Thu Apr 03, 2014 3:50 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1396 :
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.
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.
Who is online
Users browsing this forum: Bing [Bot] and 113 guests