Page 1 of 1
About Question com.enthuware.ocpjp.v7.2 _. _1083
Posted: Mon Oct 06, 2014 8:23 am
by sasha32003
Given:
Code: Select all
public class Counter{
static AtomicInteger ai = new AtomicInteger(0);
public static void increment(){
//1
}
//other valid code }
This class is supposed to keep an accurate count for the number of times the increment method is called. Several classes share this class and call its increment method. What should be inserted at //1 ?
I think there could be 3 valid answers:
1. ai.incrementAndGet();
2. ai.addAndGet(1);
3. ai.set(ai.get()+1); - What is wrong with this option?
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Mon Oct 06, 2014 11:18 am
by admin
Did you read the explanation provided with the option?
ai.set(ai.get()+1); is not atomic. It is composed of two independent method calls. It is possible for another thread to change the count in between those two calls. That is why it is not valid.
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Mon Oct 06, 2014 11:35 am
by sasha32003
admin wrote:Did you read the explanation provided with the option?
ai.set(ai.get()+1); is not atomic. It is composed of two independent method calls. It is possible for another thread to change the count in between those two calls. That is why it is not valid.
Hi. That is why I asked here. There was no such explanation.
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Mon Oct 06, 2014 11:52 am
by admin
That's weird. I do see an explanation with this option.

- 2.1083.png (27.41 KiB) Viewed 6087 times
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Tue Oct 07, 2014 1:07 am
by sasha32003
admin wrote:That's weird. I do see an explanation with this option.
The attachment 2.1083.png is no longer available
It is:
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Tue Oct 07, 2014 5:49 am
by admin
What version of the question bank are you using?
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Tue Oct 07, 2014 6:08 am
by sasha32003
admin wrote:What version of the question bank are you using?
Where do I look for version?
This is the .ets file that I am using: jqplusv7.ets
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Tue Oct 07, 2014 7:03 am
by admin
Just download the ets file from our website again. You can see the version using Tools/Check for Question Bank Update.
Re: About Question com.enthuware.ocpjp.v7.2.1083
Posted: Tue Oct 07, 2014 7:07 am
by sasha32003
admin wrote:Just download the ets file from our website again. You can see the version using Tools/Check for Question Bank Update.
Thank you.