Solved

JBOSS and Transaction ID

Posted on 2003-11-14
7
374 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
[X]
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
7 Comments
 
LVL 9

Expert Comment

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

Author Comment

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

Expert Comment

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

Author Comment

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

Accepted Solution

by:
vzilka earned 100 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.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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 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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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