Author: markt Date: Sat Jan 19 19:13:37 2013 New Revision: 1435641 URL: http://svn.apache.org/viewvc?rev=1435641&view=rev Log: Reformat
Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java Modified: tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java?rev=1435641&r1=1435640&r2=1435641&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/bugs/Bug51582.java Sat Jan 19 19:13:37 2013 @@ -27,112 +27,79 @@ import org.apache.tomcat.jdbc.pool.Conne import org.apache.tomcat.jdbc.pool.PoolConfiguration; import org.apache.tomcat.jdbc.test.DefaultProperties; +public class Bug51582 { -public class Bug51582 -{ - - /** - * @param args - * @throws SQLException - */ - public static void main(String[] args) throws SQLException - { - org.apache.tomcat.jdbc.pool.DataSource datasource = null; - PoolConfiguration p = new DefaultProperties(); - - p.setJmxEnabled(true); - p.setTestOnBorrow(false); - p.setTestOnReturn(false); - p.setValidationInterval(1000); - p.setTimeBetweenEvictionRunsMillis(2000); - - p.setMaxWait(2000); - p.setMinEvictableIdleTimeMillis(1000); - - datasource = new org.apache.tomcat.jdbc.pool.DataSource(); - datasource.setPoolProperties(p); - datasource.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx(threshold=200)"); - ConnectionPool pool = datasource.createPool(); - - - Connection con = pool.getConnection(); - Statement st = con.createStatement(); - try { - st.execute("DROP ALIAS SLEEP"); - } catch (Exception ignore) { - // Ignore - } - st.execute("CREATE ALIAS SLEEP AS $$\nboolean sleep() {\n try {\n Thread.sleep(10000);\n return true; } catch (Exception x) {\n return false;\n }\n}\n$$;"); - st.close(); - con.close(); - int iter = 0; - while ((iter++) < 10) - { - final Connection connection = pool.getConnection(); - final CallableStatement s = connection.prepareCall("{CALL SLEEP()}"); - - List<Thread> threadList = new ArrayList<>(); - - for (int l = 0; l < 3; l++) - { - final int i = l; - - Thread thread = new Thread() - { - @Override - public void run() - { - try - { - if (i == 0) - { - Thread.sleep(1000); - s.cancel(); - } - else if (i == 1) - { - //or use some other statement which will block for a longer time - long start = System.currentTimeMillis(); - System.out.println("["+getName()+"] Calling SP SLEEP"); - s.execute(); - System.out.println("["+getName()+"] Executed SP SLEEP ["+(System.currentTimeMillis()-start)+"]"); - } - else - { - Thread.sleep(1000); - connection.close(); - } - } - catch (InterruptedException e) - { - + public static void main(String[] args) throws SQLException { + org.apache.tomcat.jdbc.pool.DataSource datasource = null; + PoolConfiguration p = new DefaultProperties(); + p.setJmxEnabled(true); + p.setTestOnBorrow(false); + p.setTestOnReturn(false); + p.setValidationInterval(1000); + p.setTimeBetweenEvictionRunsMillis(2000); + p.setMaxWait(2000); + p.setMinEvictableIdleTimeMillis(1000); + datasource = new org.apache.tomcat.jdbc.pool.DataSource(); + datasource.setPoolProperties(p); + datasource.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx(threshold=200)"); + ConnectionPool pool = datasource.createPool(); + Connection con = pool.getConnection(); + Statement st = con.createStatement(); + try { + st.execute("DROP ALIAS SLEEP"); + } catch (Exception ignore) { + // Ignore + } + st.execute("CREATE ALIAS SLEEP AS $$\nboolean sleep() {\n try {\n Thread.sleep(10000);\n return true; } catch (Exception x) {\n return false;\n }\n}\n$$;"); + st.close(); + con.close(); + int iter = 0; + while ((iter++) < 10) { + final Connection connection = pool.getConnection(); + final CallableStatement s = connection.prepareCall("{CALL SLEEP()}"); + List<Thread> threadList = new ArrayList<>(); + for (int l = 0; l < 3; l++) { + final int i = l; + Thread thread = new Thread() { + + @Override + public void run() { + try { + if (i == 0) { + Thread.sleep(1000); + s.cancel(); + } else if (i == 1) { + // or use some other statement which will block + // for a longer time + long start = System.currentTimeMillis(); + System.out.println("[" + getName() + + "] Calling SP SLEEP"); + s.execute(); + System.out.println("[" + getName() + + "] Executed SP SLEEP [" + + (System.currentTimeMillis() - start) + + "]"); + } else { + Thread.sleep(1000); + connection.close(); + } + } catch (InterruptedException e) { + } catch (SQLException e) { + e.printStackTrace(); + } + } + }; + threadList.add(thread); + thread.start(); } - catch (SQLException e) - { - e.printStackTrace(); + for (Thread t : threadList) { + try { + t.join(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - - } - - }; - threadList.add(thread); - thread.start(); - } - for (Thread t : threadList) - { - try - { - t.join(); } - catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - - } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org