import java.sql.*; import javax.sql.XAConnection; import org.postgresql.xa.PGXADataSource; public class XaCloseTest { public static void main(String args[]) throws Exception { PGXADataSource ds = new PGXADataSource(); ds.setServerName("localhost"); ds.setUser("kjurka"); ds.setPassword(""); ds.setDatabaseName("kjurka"); ds.setPortNumber(5850); XAConnection xaconn = ds.getXAConnection(); Handle h = new Handle(); h.conn = xaconn.getConnection(); for (int i=0; i<5; i++) { Closer c = new Closer(h); c.start(); } Opener o = new Opener(xaconn, h); o.start(); } private static class Handle { public Connection conn; } private static class Closer extends Thread { private final Handle _h; public Closer(Handle h) { _h = h; } public void run() { while (true) { try { _h.conn.close(); } catch (SQLException sqle) { sqle.printStackTrace(); } } } } private static class Opener extends Thread { private final XAConnection _xaconn; private final Handle _h; public Opener(XAConnection xaconn, Handle h) { _xaconn = xaconn; _h = h; } public void run() { while (true) { try { _h.conn = _xaconn.getConnection(); } catch (SQLException sqle) { sqle.printStackTrace(); } } } } }