Created
January 1, 2015 12:45
-
-
Save maxant/d7d44d200de36c068c48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.maxant.async; | |
import java.util.concurrent.Future; | |
import javax.annotation.Resource; | |
import javax.ejb.EJB; | |
import javax.ejb.Stateless; | |
import javax.ejb.TransactionAttribute; | |
import javax.ejb.TransactionAttributeType; | |
import javax.ejb.TransactionManagement; | |
import javax.ejb.TransactionManagementType; | |
import javax.transaction.TransactionSynchronizationRegistry; | |
@TransactionManagement(TransactionManagementType.CONTAINER) | |
@Stateless | |
public class Service1 { | |
@Resource private TransactionSynchronizationRegistry tsr; | |
@EJB private Service2 service; | |
@TransactionAttribute(TransactionAttributeType.REQUIRED) | |
public Future<String> foo() { | |
String value = "TEST"; | |
tsr.putResource(Service2.KEY, value); | |
String s = "<br>Service1: threadId=" + Thread.currentThread().getId() + ", tsrResourceValue=" | |
+ tsr.getResource(Service2.KEY) + ", txKey=" + tsr.getTransactionKey() + ", txStatus=" | |
+ tsr.getTransactionStatus(); | |
return service.foo(s); | |
} | |
} | |
// from javax.transaction.Status: | |
// public static final int STATUS_ACTIVE = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment