Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Transactions in Web Components  RSS feed

Trevor Pereira
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I want to update a file every 60 seconds. Now I have created a class that extends Thread which sleeps for 60 seconds and I have also tried using java.util.Timer. However, I am getting a log file that is being generated as follows (using Websphere 5.0)
J2CA0075W: An active transaction should be present while processing method allocateMCWrapper.
I know that these messages "are being produced due to an unsupported environment. When an application is spinning its own threads from an EJB, spinning a thread and accessing a database is not supported" (from ibm site)
This is per the J2ee specification:
A Web component may only start a transaction in its service method. A transaction that is started by a servlet or JSP page must be completed before the service method returns. In other words, transactions may not span Web requests.
There are many subtle and complex interactions between the use of JTA transactions, threads, and JDBC connections. Web components should follow the guidelines stated in the transaction management chapter of the J2EE specification:
JTA transactions should be started and completed only from the thread in which the service method is called. If the Web component creates additional threads for any purpose, these threads should not attempt to start JTA transactions.
JDBC connections may be acquired and released by a thread other than the service method thread, but should not be shared between threads.
JDBC Connection objects should not be stored in static fields.
For Web components implementing SingleThreadModel, JDBC Connection objects may be stored in class instance fields.
For Web components not implementing SingleThreadModel, JDBC Connection objects should not be stored in class instance fields, and should be acquired and released within the same invocation of the service method.
If I can not use a Thread (and I would guess that I cannot use Timer because it also uses a Thread) what would you recommend?
Thanks in advance
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!