Skip to content

Instantly share code, notes, and snippets.

@maxant
Created January 1, 2015 12:45
Show Gist options
  • Save maxant/d7d44d200de36c068c48 to your computer and use it in GitHub Desktop.
Save maxant/d7d44d200de36c068c48 to your computer and use it in GitHub Desktop.
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