• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transactions

 
khaled Jamal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

An enterprise bean's timeout callback method can only have a REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED transaction attribute

Let me know please why An enterprise bean's timeout callback supports REQUIRES_NEW

Thanks
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4670
325
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The REQUIRES_NEW is useful here, if the timeout method is used to perform some *risky* task. For an example, if this timeout method is used to update email addresses on a separate database, it is a good practice to use the REQUIRES_NEW attribute here, so it is executed within a new transaction. If the transaction is marked for the rollback in this case, it will rollback the new transaction, and will not cause any side effects with the bean. But if you used REQUIRED attribute here, and if the transaction is rolledback, the timer will be implicitly canceled with transaction rollback. So, if you used this timer to complete some periodic tasks, further invocations on that will not be done.

Devaka.
 
khaled Jamal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Devaka, I got it
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you used REQUIRED attribute here, and if the transaction is rolledback, the timer will be implicitly canceled with transaction rollback. So, if you used this timer to complete some periodic tasks, further invocations on that will not be done.


Devaka,
The @Timeout method is the method which gets triggered periodically, the actually timer creation is usually done in a different business method. So if the transaction rolls back in the @Timeout method, the timer should not be cancelled. Here is some supporting documentation from the spec. An interesting sidenote is that in both the cases of Required and Requires_New, a new transaction is created for the execution of the @Timeout method.

18.2.5 Transactions
An enterprise bean typically creates a timer within the scope of a transaction. If the transaction is then
rolled back, the timer creation is rolled back.

An enterprise bean typically cancels a timer within a transaction. If the transaction is rolled back, the
container rescinds the timer cancellation.

The timeout callback method is typically has transaction attribute REQUIRED or REQUIRES_NEW
(Required or RequiresNew if the deployment descriptor is used to specify the transaction
attribute). If the transaction is rolled back, the container retries the timeout.


Note that the container must start a new transaction if the REQUIRED (Required) transaction
attribute is used. This transaction attribute value is allowed so that specification of a
transaction attribute for the timeout callback method can be defaulted.
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you used REQUIRED attribute here, and if the transaction is rolledback, the timer will be implicitly canceled with transaction rollback. So, if you used this timer to complete some periodic tasks, further invocations on that will not be done.


Devaka,
The @Timeout method is the method which gets triggered periodically, the actually timer creation is usually done in a different business method. So if the transaction rolls back in the @Timeout method, the timer should not be cancelled. Here is some supporting documentation from the spec. An interesting sidenote is that in both the cases of Required and Requires_New, a new transaction is created for the execution of the @Timeout method.

18.2.5 Transactions
An enterprise bean typically creates a timer within the scope of a transaction. If the transaction is then
rolled back, the timer creation is rolled back.

An enterprise bean typically cancels a timer within a transaction. If the transaction is rolled back, the
container rescinds the timer cancellation.

The timeout callback method is typically has transaction attribute REQUIRED or REQUIRES_NEW
(Required or RequiresNew if the deployment descriptor is used to specify the transaction
attribute). If the transaction is rolled back, the container retries the timeout.


Note that the container must start a new transaction if the REQUIRED (Required) transaction
attribute is used. This transaction attribute value is allowed so that specification of a
transaction attribute for the timeout callback method can be defaulted.
 
Marcin Faryna
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I understand this way:

1.Timer is created within transaction so rollback of this transaction imply timer creation will not happend.
2.Timer has its own transaction when it's timeOut method is invoked. What is is interesting here in spec "The timeout callback method is typically has transaction attribute REQUIRED or REQUIRES_NEW (Required or RequiresNew if the deployment descriptor is used to specify the transaction attribute)", REQUIRED suggests that timer timeOut method may join some other transaction which i think is not possible?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic