import java.sql.*; public class ThreadConnection { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); for (int i=0; i<20; i++) { Connector con = new Connector(i+1); new Thread(con, "Conn").start(); } } static class Connector implements Runnable { private int _num; Connector(int n) { _num = n; } public void run() { for (int i=0; i<1000; i++) { try { Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka",""); // System.out.println("Connector " + _num + " made connection #" + (i+1)); conn.close(); } catch (SQLException sqle) { sqle.printStackTrace(); System.exit(1); } } } } }