[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


JBOSS and Transaction ID

Posted on 2003-11-14
Medium Priority
Last Modified: 2010-03-17
We are writing some classed that will log some information to the database that we will use later to generate activity reports.  Within a given transaction, there may be more than one activity occurring.  For example, if you download a file, you must first access the file to download it.  We would like to be able to link two activities (access and download) to the same transaction.  Is there a way in JBoss or through the java sun core api's to obtain the transaction id so that we can log it along with the activity?
Question by:pcarrollnf
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 9752181
How are you trying to do it? By writing code inside your application or trying something external?

The basic thing to remember here is that the same execution thread runs your transaction (assuming your transaction does not span across machines, and that you remember that MDBs don't run in the same transaction as the code that sent the JMS message). If you have multiple transactions created by the same user request (do not do this, you get a major performance hit), they will all run by the same execution thread.

You can get the Thread id by using the command Thread.currentThread().

Now, either you log this in your application by hand, or you use some other ways, like:
1. JBoss 4.0 AOP.
2. Aspect/J
3. Write your own class loading mechanism.

I don't recommend any of them. The first two are based on AOP, which is a fairly new technology. The third requires enormous amounts of code to write. Also, the first and third solutions make your code totally unmigratable to other application servers.

So, to summarize, use Thread.currentThread(). It will print the thread unique ID.
One last thing - the same thread can be reused after the user request ends, so make sure you write to the log when the user request is finished.

Author Comment

ID: 9754114
I want to pass the transaction id to the JMS topic, along with some other information, and then let it do its own thing.  I have control of what activities are logged.  If I can get the transaction id, I will only log it with certain activities.  I was hoping that JBOSS may have a method implemented where you could easily obtain the transaction id or that I could easily obtain it by using the javax.transaction api's.  If neither can be done, then it is probably not worth the extra effort at this point in the project.  If anyone knows how to obtain that transaction ID, I'd appreciate the info.

I tried the Thread.currentThread() but this did not give me useful information.

Expert Comment

ID: 9756789
What information do you need? a unique id in the system?

Author Comment

ID: 9756926
I need the unique ID for the transaction.  I assume that JBOSS may need a transaction ID to keep track of the transaction itself.  I was hoping that I could obtain that transaction id if it exists.

Accepted Solution

vzilka earned 400 total points
ID: 9757881
There is an interface called XID, which does exactly what you want.
However, this interface is internal for the application server implementors.
You will have to write your own code for identifying transactions.

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack or Above. The following steps a…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question