final boolean enlisted;
enlisted = om.getTransaction().isActive();
mc = cf.getConnection(enlisted ? om : null, null); // Will throw exception if already locked
// Lock the connection now that it is in use by the user
mc.lock();
Runnable closeRunnable = new Runnable() {
public void run() {
// Unlock the connection now that the user has finished with it
mc.unlock();