System.setSecurityManager(new RMISecurityManager());
ServiceFinder sf = new ServiceFinder(TransactionManager.class);
TransactionManager txm = (TransactionManager)(sf.getObject());
Transaction.Created resp =
TransactionFactory.create(txm, Lease.FOREVER);
LeaseRenewalManager lrm = new LeaseRenewalManager();
lrm.renewUntil(resp.lease, Lease.FOREVER, null);
boolean commit = true;
try {
// Do some transaction based operations here, passing
// resp.transaction to services that need it
} catch (Exception e) {
commit = false;
}
if (commit)
resp.transaction.commit();
else resp.transaction.abort();
// The transaction lease was cancelled as a side-effect of
// the commit
lrm.remove(resp.lease);