Solved

JBOSS and Transaction ID

Posted on 2003-11-14
7
355 Views
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?
0
Comment
Question by:pcarrollnf
  • 3
  • 2
7 Comments
 
LVL 9

Expert Comment

by:vzilka
Comment Utility
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.
0
 

Author Comment

by:pcarrollnf
Comment Utility
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.
0
 
LVL 9

Expert Comment

by:vzilka
Comment Utility
What information do you need? a unique id in the system?
0
 

Author Comment

by:pcarrollnf
Comment Utility
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.
0
 
LVL 9

Accepted Solution

by:
vzilka earned 100 total points
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 7.0.0.23 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 …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now