what is the value of the size variable when control reaches Line 18?

A developer implements a stateless session bean as a timed object. The bean contains two local
business methods with the transaction attribute REQUIRED.

A client begins a UserTransaction and calls the foo local business method. The foo method
returns five seconds later. The client rolls back the transaction and then calls the bar local
business method. Assuming there have been no other client invocations on the stateless session
bean, what is the value of the size variable when control reaches Line 18?

A developer implements a stateless session bean as a timed object. The bean contains two local
business methods with the transaction attribute REQUIRED.

A client begins a UserTransaction and calls the foo local business method. The foo method
returns five seconds later. The client rolls back the transaction and then calls the bar local
business method. Assuming there have been no other client invocations on the stateless session
bean, what is the value of the size variable when control reaches Line 18?

A.
0

B.
1

C.
-1

Explanation:
An enterprise bean usually creates a timer within a transaction. If this transaction is
rolled back,the timer creation also is rolled back.
The transaction will roll back. The creation of the timer will rock back. There will be zero timers.
Note: The UserTransaction interface defines the methods that allow an application to explicitly
manage transaction boundaries.
rollback() rolls back the transaction associated with the current thread.
Note 2: size()
Returns the number of elements in this collection. If this collection contains more than
Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Reference: The Java EE 6Tutorial. PartNo: 821 Transactions andTimers



Leave a Reply 4

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


Alex

Alex

I have doubts with this.
If client can rollback a transaction via UserTransaction, then it’s BMT. If BMT, when it calls foo() transaction is suspended and EJB creates a new transaction (it’s CMT as it supports REQUIRED). As it is stateless when foo() ends new transaction is commited and it doesn’t matter what the client do with it’s transaction. Then answer should be B.
Am I wrong?

Oscar

Oscar

A. Client is BMT. When BMT invokes CMT session bean the transaction is propagated. If CMT/BMT invokes BMT session bean the transaction is suspended.