A developer writes a Singleton bean that uses the java Persistence API within a business method:
Two different concurrently executing caller threads acquire an EJB reference to PersonBean and
each invoke the getPerson () method one time. How many distinct transaction are used to process
the caller invocations?
A.
0
B.
1
C.
2
Explanation:
Only one transaction is required. LockType READ allows simultaneous access to
singleton beans.
Note: READ
public static final LockType READ
For read-only operations. Allows simultaneous access to methods designated as READ, as long
as no WRITE lock is held.
Reference: javax.ejb, Enum LockType
2
Why 2?
They use LockType.READ,so the container will let multiple threads run simultaneously over getPerson method. However, a transaction context is associated with a thread. So, for each thread, a separate transaction context will be created (since none is not associated with the client already).
My answer is C – two transactions
C