final boolean enlisted;
enlisted = ec.getTransaction().isActive();
mc = cf.getConnection(enlisted ? ec : null, ec.getTransaction(), 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();