About Question enthuware.ocpjp.v7.2.1366 :

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

Moderator: admin

Post Reply
shamran99
Posts: 15
Joined: Wed May 10, 2017 2:49 am
Contact:

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

Post by shamran99 »

Hi,

Just need to clarify on the following.
The answer says..
"Numbers 1 to 5 will be printed (some may be repeated or missed) with "N Done" anywhere in the sequence where N cannot be determined."

I answered...
"Total of 5 numbers will be printed followed by "N Done" where N cannot be determined."
considering the following scenario as well.

Since the threadCounter variable is not defined volatile, the changes might not be visible to other threads. So there is a possibility to get 5 times the number 1 printed. Am I wrong? PLease explain.

Regards,
Shamran.

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

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

Post by admin »

If you access a variable from within a synchronized block, then volatile is not required. Synchronization guarantees that most recent update will be visible to accessor thread.
If you like our products and services, please help us by posting your review here.

teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

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

Post by teodorj »

Option 4 is wrong because of the line in the main method..

System.out.println(threadcounter+" DONE");

any numbers (1-5) will be printed (from run) then the main method will print the thread counter value .
So it is not equal to 5 numbers

Am I correct?

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

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

Post by admin »

No, that option says, 5 numbers and then N done also. So, 6 numbers is not the problem with this option. Please read the explanation carefully. It explains why it is wrong.
If you like our products and services, please help us by posting your review here.

teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

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

Post by teodorj »

Option 4 is also not correct because of the bold part..
Total of 5 numbers will be printed followed by "N Done" where N cannot be determined.

This is wrong because the order in which the print method in main cannot be determined.
Please verify.

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

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

Post by admin »

Correct.
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 63 guests