Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Transactions, Suspension, and the Ticking Clock

Keep it short - and don't time out

This month's article is again inspired by a posting on the weblogic.developer.interest.transaction newsgroup. The question (excerpted from the posting) was:

Does the <trans-timeout-seconds>10</trans-timeout-seconds> in weblogic-ejb-jar.xml apply to transactions that are in a suspended state? I have EJB1 (Container Managed/Required) that starts transaction T1 and does some work, then calls another EJB, EJB2 (Container Managed/NotSupported), which makes an interdomain T3 call. Since EJB2 is configured with NotSupported transaction attribute, transaction T1 is suspended for the time being while the business method of EJB2 is executing. The question is, if I set <trans-timeout-seconds>10</trans-timeout-seconds> for transactions started by EJB1, will it work?

The answer is yes. End of article.

Only joking! The subject of transaction timeouts and their relationship to the flow of control through an application's logic is one that often comes up, and is frequently misunderstood, so here goes another journey through "how the bits fit together."

First, a step back. As you will know if you have read my previous articles (or any other sources of information about distributed transactions), long-running XA transactions are a bad thing. Database (and potentially other) locks are held from the moment that a transaction touches the data until the point that it commits or aborts. Lots of locked data can quickly become a performance problem for any application, resulting ultimately in your whole database being locked. This is bad. The moral of that story is, keep your XA transactions as short as you possibly can to allow locks to be recycled as fast as possible.

In this context, the transaction timeout is your friend. You can set a timeout in a deployment descriptor, programmatically in your code, or via the JTA page in the BEA WebLogic console and the transaction manager will respect this timeout on your behalf. If a transaction lasts longer than the timeout permits, WebLogic's transaction manager will automatically go about rolling it back for you. The assumption is that some kind of application error (anything from a logic error to the hardware being temporarily overloaded, causing the application to run slowly) is causing the timeout to be exceeded, and that cleaning up the transaction (and thus freeing the associated locks) will help the overall health and well-being of the system.

So that's fine. That's what the transaction timeout is, and that's what it's for. Generally, tuning transaction timeout values such that transactions in a smoothly running system will never time out (by a small margin of safety) offers you a degree of protection from spikes in load and errors in logic that can turn little localized dramas into big, scary catastrophes.

As Usual, the Transaction Manager Is Your Friend
So far so clear. The confusion tends to lie with how the transaction timeout relates to other behaviors of the application server. The behaviors in question are how the timeout mechanism behaves with respect to a suspended transaction (the basis of the posting I opened with) and what happens to threads executing code on behalf of transactions that time out?

So what is suspension of a transaction? Recall that transactions have two halves. The synchronous runtime part keeps track of what application actions should be logically grouped into a transaction (controlled, by calls to begin, commit, etc.) and the asynchronous part whose obvious function is to take the list of resources collected by the runtime part and process the two-phase commit asynchronously with respect to the application flow. What the calls to UserTransaction.begin do is associate a transaction object with the current thread of execution. The fact that a transaction is associated with a thread of execution tells the application-server infrastructure to propagate the transaction along with any calls or data accesses the thread makes. A call to UserTransaction.commit disassociates the transaction object and the current thread and kicks off the two-phase commit of the (now-completed) transaction. What suspending a transaction does is simply break the association between a thread of execution and a transaction. Resuming it rebuilds the association. Thus, if you need to work outside of an active transaction, you suspend it, do the work, and then resume it when you're done.

There is one more necessary detail here: the life cycles of the synchronous and asynchronous components do not follow each other serially. Both begin concurrently when the UserTransaction.begin call is made. The synchronous part clearly ends before the asynchronous part, since the two-phase commit processing that is the latter's primary responsibility cannot begin until the synchronous piece has completed - completion signalled by calling commit.

Given the rationale I have laid out for the timeout's existence, it should be clear that the other duty performed by the asynchronous component of the transaction is timeout processing. From the moment the begin call is made, the timer starts ticking independently of the flow of your processing. When the timeout expires, the Transaction Manager will roll the transaction back. The first you hear of that happening may be when calls you make in the thread associated with the transaction start to throw exceptions, since it is not possible to propagate a rolled-back transaction (what would be the point, the results of the call will not persist under any circumstances?).

After all that, the direct answer to the question we started with is that suspending a transaction has no impact whatsoever on its timeout; it simply breaks the association between transaction and thread. If your code suspends a transaction and then goes to sleep for a week, it should expect to find that the transaction has timed out while it slept.

The Transaction Has Timed Out While It Slept
Finally, to the second relationship I mentioned - that between the timed-out transaction and the thread currently executing work on the transaction's behalf. Some people hope that if they set a transaction timeout on an operation, when the timeout is exceeded all work on behalf of the transaction will instantly stop. In an ideal world, that would happen (and WebLogic does all it can to try and stop you wasting cycles by refusing to propagate a timed-out transaction), but the world (and the world I am referring to here is the general world of java) is not ideal. So the transaction times out, and WebLogic wants to stop your thread. What can it do? Looking at the java.lang.Thread class, we quickly conclude that it can't do a whole lot. It could call Thread.interrupt, but then code inside the thread would have to catch the Interrupt and clean up - so this requires cooperation for the application code. It could call Thread.destroy, but according to the Javadoc this is not implemented (and if it was, would leave no way to clean up resources). Or it could call Thread.stop() except that that's deprecated with a mile-long health warning that talks about how stopping a thread with no controlled cleanup could lead to all sorts of inconsistent data being left around.

There is no easy answer - there isn't really a facility in J2SE or J2EE as they stand today to allow a thread to be safely and asynchronously terminated. WebLogic does what it can - the node manager will try and detect "stuck" threads to warn operators about them; the runtime will try and prevent work continuing on behalf of rolled-back transactions by throwing exceptions rather than propagating them. And, it does all it can at the JDBC level (such as calling Statement.cancel for statements running on behalf of rolling back transactions where possible) but at the end of the day - until the thread returns control to the container - there isn't much more WebLogic can do than wait.

In summary, the transaction timeout impacts the asynchronous behavior of the transaction manager only - it has no direct impact whatsoever on the flow of control within the application logic.

I have timed out again for another month. Roll back and read more next time!

More Stories By Peter Holditch

Peter Holditch is a senior presales engineer in the UK for Azul Systems. Prior to joining Azul he spent nine years at BEA systems, going from being one of their first Professional Services consultants in Europe and finishing up as a principal presales engineer. He has an R&D background (originally having worked on BEA's Tuxedo product) and his technical interests are in high-throughput transaction systems. "Of the pitch" Peter likes to brew beer, build furniture, and undertake other ludicrously ambitious projects - but (generally) not all at the same time!

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Dhilip Krishnan 04/14/04 04:57:01 PM EDT

Hi Peter,

I am glad to read your article on transaction timeout and suspended transactions. The insight you provided is very useful. Its me who posted the question with bea earlier.

Espically the section "The Transaction Has Timed Out While It Slept", provides useful insight into how transaction manager handles timedout transactions.

The biggest lesson I learned while investigating this issue was not to mix up transaction attributes amoung resources while using multiple resources in a single transaction. If you have three ejbs invoking one after the other in a chain, your are better off setting all of the ejb''s transaction attributes to either "Required" or "Not Required".

@ThingsExpo Stories
SYS-CON Events announced today that Daiya Industry will exhibit at the Japanese Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ruby Development Inc. builds new services in short period of time and provides a continuous support of those services based on Ruby on Rails. For more information, please visit https://github.com/RubyDevInc.
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
As businesses evolve, they need technology that is simple to help them succeed today and flexible enough to help them build for tomorrow. Chrome is fit for the workplace of the future — providing a secure, consistent user experience across a range of devices that can be used anywhere. In her session at 21st Cloud Expo, Vidya Nagarajan, a Senior Product Manager at Google, will take a look at various options as to how ChromeOS can be leveraged to interact with people on the devices, and formats th...
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
SYS-CON Events announced today that SourceForge has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. SourceForge is the largest, most trusted destination for Open Source Software development, collaboration, discovery and download on the web serving over 32 million viewers, 150 million downloads and over 460,000 active development projects each and every month.
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities – ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups. As a result, many firms employ new business models that place enormous impor...
SYS-CON Events announced today that TidalScale will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale is the leading provider of Software-Defined Servers that bring flexibility to modern data centers by right-sizing servers on the fly to fit any data set or workload. TidalScale’s award-winning inverse hypervisor technology combines multiple commodity servers (including their ass...
As popularity of the smart home is growing and continues to go mainstream, technological factors play a greater role. The IoT protocol houses the interoperability battery consumption, security, and configuration of a smart home device, and it can be difficult for companies to choose the right kind for their product. For both DIY and professionally installed smart homes, developers need to consider each of these elements for their product to be successful in the market and current smart homes.
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
As hybrid cloud becomes the de-facto standard mode of operation for most enterprises, new challenges arise on how to efficiently and economically share data across environments. In his session at 21st Cloud Expo, Dr. Allon Cohen, VP of Product at Elastifile, will explore new techniques and best practices that help enterprise IT benefit from the advantages of hybrid cloud environments by enabling data availability for both legacy enterprise and cloud-native mission critical applications. By rev...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp emp...
SYS-CON Events announced today that Dasher Technologies will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we'v...
SYS-CON Events announced today that TidalScale, a leading provider of systems and services, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale has been involved in shaping the computing landscape. They've designed, developed and deployed some of the most important and successful systems and services in the history of the computing industry - internet, Ethernet, operating s...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant tha...
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
Amazon is pursuing new markets and disrupting industries at an incredible pace. Almost every industry seems to be in its crosshairs. Companies and industries that once thought they were safe are now worried about being “Amazoned.”. The new watch word should be “Be afraid. Be very afraid.” In his session 21st Cloud Expo, Chris Kocher, a co-founder of Grey Heron, will address questions such as: What new areas is Amazon disrupting? How are they doing this? Where are they likely to go? What are th...