Solved

JBOSS and Transaction ID

Posted on 2003-11-14
7
369 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
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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 …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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