Which represents the set of all possible coordinate values [X, Y] returned to the reader threads?

A developer writes a Singleton bean that holds state for a single coordinate:

An update thread acquires an EJB reference to CoordinateBean and alternates between invoking
SetCoordinate (0, 0) and SetCoordinate (1, 1) in a loop.
At the same time, ten reader threads each acquire an EJB reference to CoordinateBean and
invoke getCoordinate () in a loop.
Which represents the set of all possible coordinate values [X, Y] returned to the reader threads?

A developer writes a Singleton bean that holds state for a single coordinate:

An update thread acquires an EJB reference to CoordinateBean and alternates between invoking
SetCoordinate (0, 0) and SetCoordinate (1, 1) in a loop.
At the same time, ten reader threads each acquire an EJB reference to CoordinateBean and
invoke getCoordinate () in a loop.
Which represents the set of all possible coordinate values [X, Y] returned to the reader threads?

A.
[0, 0]

B.
[1, 1]

C.
[0, 0], [1, 1]

D.
[0, 0], [0, 1], [1, 0], [1, 1]

Explanation:
The value could be either [0,0] or [1,1].
Note:
Java has several design patterns Singleton Pattern being the most commonly used. Java
Singleton patternbelongs to the family of design patterns, that govern the instantiation process.
This design pattern proposes that at any time there can only be one instance of a singleton
(object) created by the JVM.



Leave a Reply 8

Your email address will not be published. Required fields are marked *


Alex

Alex

C. Not D because:
JSR 318 – Enterprise JavaBeans 3.1, Final Release: 4.8.5.4 Specification of the Container Managed Concurrency Metadata for a Bean’s Methods
By default, the value of the lock associated with a method of a bean with container managed concurrency demarcation is Write(exclusive), and the concurrency lock attribute does not need to be explicitly specified in this case.

Mohamed Fayek

Mohamed Fayek

yes the correct answer should be C

Miecho

Miecho

Although correct answer is C, the question is misleading at least. There is single Coordinate object shared among multiple threads, Lock is acquired only for the duration of getCoordinate() and setCoordinate(). From my point of view this is not proper synchronization, because threads can see values of [0, 0], [1, 0], [0, 1] and [1, 1] in this single Coordinate object.

JavaBatman

JavaBatman

Nope its B!!!