• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Transactions

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 6801
1298
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Devaka, I got it
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic