{
public static void testSuspendResumeParticipants()
throws Exception
{
UserTransaction ut = UserTransaction.getUserTransaction();
TransactionManager tm = TransactionManager.getTransactionManager();
DemoDurableParticipant p1 = new DemoDurableParticipant();
DemoDurableParticipant p2 = new DemoDurableParticipant();
DemoDurableParticipant p3 = new DemoDurableParticipant();
DemoDurableParticipant p4 = new DemoDurableParticipant();
System.out.println("Starting first transaction.\n");
ut.begin();
try {
tm.enlistForDurableTwoPhase(p1, p1.identifier());
tm.enlistForDurableTwoPhase(p2, p2.identifier());
tm.enlistForDurableTwoPhase(p3, p3.identifier());
tm.enlistForDurableTwoPhase(p4, p4.identifier());
TxContext ctx = tm.suspend();
System.out.println("Suspended: "+ctx);
ut.begin();
System.out.println("\nStarted second transaction.");
tm.resume(ctx);
System.out.println("\nCommitting first transaction.\n");
} catch (Exception eouter) {
try {
ut.rollback();
} catch(Exception einner) {
}
throw eouter;
}
ut.commit();
}