yes XTS is thread safe. Even thought we do have a single instance of the UserTransaction class, it operates using the information available on the current thread (we use java.lang.ThreadLocal there).
I'm a bit surprised because I don't understand how can UserTransaction be thread safe and have some errors I was(am) getting. I understand that:
UserTransaction t = UserTransactionFactory.userTransaction();
Fills UserTransaction object with the values required for the current thread but what happens if at the same moment another Thread invokes the same instruction?, what I think is that the first Thread will see the modifications of the second. Or am I missing something?
This is based on my observation, originally I was creating a UserTransaction object in the start of a task and using the same object to commit or rollback in the end. If in the meantime I was receiving a WS call I was creating a "new" UserTransaction and the original task was commiting the transaction for the WS instead of its own. I minimized the errors by calling UserTransaction.userTransaction before the commit but I could still have race conditions
To answer your question "what happens if at the same moment another Thread invokes the same instruction?":
UserTransaction object will always be the same for every thread. However, transaction information associated with the thread is different, based on the information received with WS request. Transaction context associated with the thread is handled by the context manager (narayana/XTS/WSTX/classes/com/arjuna/mwlabs/wst/at/remote/ContextManager.java at 4.17.13.Final · jbosstm/narayana · GitH…).
Second part of the message is not very clear to me. Could you provide the stack trace with an error message. And also clarify the scenario which is failing?
I agree with Gytis, this does sound strange. Can you provide a simple reproducer so we can see it happening? This will make it a lot easier for us to fix or identify what you are doing wrong.
It may have been my own mistake, I'm testing it and will provide more information as soon as I have one conclusion