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.
About Question enthuware.ocpjp.v7.2.1366 :
Moderator: admin
-
- Posts: 15
- Joined: Wed May 10, 2017 2:49 am
- Contact:
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1366 :
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.
-
- Posts: 33
- Joined: Tue Jun 19, 2018 10:27 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1366 :
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?
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?
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1366 :
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.
-
- Posts: 33
- Joined: Tue Jun 19, 2018 10:27 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1366 :
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.
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.
-
- Site Admin
- Posts: 10045
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1366 :
Correct.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 63 guests