Package org.apache.tomcat.jdbc.pool

Examples of org.apache.tomcat.jdbc.pool.ConnectionPool


        this.datasource.setMaxActive(1);
        this.datasource.setMinIdle(datasource.getMaxActive());
        this.datasource.setMaxIdle(datasource.getMaxActive());
        this.datasource.setUsername(username);
        this.datasource.getConnection().close();
        ConnectionPool pool = datasource.createPool();
    }
View Full Code Here


                }
            }).start();
        }

        openedLatch.await();
        ConnectionPool pool = ds.getPool();
        //Now we have 3 initialized busy connections
        Assert.assertEquals(0, pool.getIdle());
        Assert.assertEquals(threadsCount, pool.getActive());
        Assert.assertEquals(threadsCount, pool.getSize());

        List<Thread> threads = new ArrayList<Thread>();
        for (int i = 0; i < threadsCount; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        ds.getConnection();
                    } catch (Exception e) {
                        System.err.println("Step 2:"+e.getMessage());
                    }
                }
            });
            thread.start();
            threads.add(thread);
        }
        for (Thread thread : threads) {
            thread.interrupt();
        }
        for (Thread thread : threads) {
            thread.join();
        }
        //Still 3 active connections
        Assert.assertEquals(0, pool.getIdle());
        Assert.assertEquals(threadsCount, pool.getActive());
        Assert.assertEquals(threadsCount, pool.getSize());

        toCloseLatch.countDown();
        closedLatch.await();

        //Here comes the bug! No more active connections and unable to establish new connections.

        Assert.assertEquals(threadsCount, pool.getIdle()); // <-- Should be threadsCount (3) here
        Assert.assertEquals(0, pool.getActive());
        Assert.assertEquals(threadsCount, pool.getSize());

        final AtomicInteger failedCount = new AtomicInteger();
        final ArrayBlockingQueue<Connection> cons = new ArrayBlockingQueue<Connection>(threadsCount);
        threads.clear();
        for (int i = 0; i < threadsCount; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        cons.add(ds.getConnection());
                    } catch (PoolExhaustedException e) {
                        failedCount.incrementAndGet();
                        System.err.println("Step 3:"+e.getMessage());
                    } catch (Exception e) {
                        System.err.println("Step 4:"+e.getMessage());
                        throw new RuntimeException(e);
                    }
                }
            });
            thread.start();
            threads.add(thread);
        }

        for (Thread thread : threads) {
            thread.join();
        }
        Assert.assertEquals(0, failedCount.get());

        Assert.assertEquals(0, pool.getIdle());
        Assert.assertEquals(threadsCount, pool.getActive());
        Assert.assertEquals(threadsCount, pool.getSize());
        for (Connection con : cons) {
            con.close();
        }
        Assert.assertEquals(threadsCount, pool.getIdle());
        Assert.assertEquals(0, pool.getActive());
        Assert.assertEquals(threadsCount, pool.getSize());
    }
View Full Code Here

        prop.putAll(properties);
        updateProperties(prop, converted, null);

        final PoolConfiguration config = build(PoolProperties.class, converted);
        config.setDataSource(ds);
        final ConnectionPool pool;
        try {
            pool = new ConnectionPool(config);
        } catch (SQLException e) {
            throw new IllegalStateException(e);
        }
        return build(TomEEDataSource.class, new TomEEDataSource(config, pool, name), converted);
    }
View Full Code Here

        String domain = "tomcat.jdbc";
        Hashtable<String,String> properties = new Hashtable<String,String>();
        properties.put("type", "ConnectionPool");
        properties.put("class", this.getClass().getName());
        oname = new ObjectName(domain,properties);
        ConnectionPool pool = datasource.createPool();
        org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = new org.apache.tomcat.jdbc.pool.jmx.ConnectionPool(pool);
        mbs.registerMBean(jmxPool, oname);

    }
View Full Code Here

    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) {}
    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<Thread>();

      for (int l = 0; l < 3; l++)
View Full Code Here

            ResultSet rs = st.executeQuery();
            rs.close();
            st.close();
        }
        System.out.println("Stats:"+stats);
        ConnectionPool pool = datasource.getPool();
        con.close();
        tearDown();
        //make sure we actually did clean up when the pool closed
        assertNull(SlowQueryReport.getPoolStats(pool.getName()));
    }
View Full Code Here

        assertEquals(1,map.size());
        String key = map.keySet().iterator().next();
        SlowQueryReport.QueryStats stats = map.get(key);
        System.out.println("Stats:"+stats);
        ClientListener listener = new ClientListener();
        ConnectionPool pool = datasource.getPool();
        ManagementFactory.getPlatformMBeanServer().addNotificationListener(
                SlowQueryReportJmx.getObjectName(SlowQueryReportJmx.class, pool.getName()),
                listener,
                null,
                null);

        for (int i=0; i<count; i++) {
            PreparedStatement st = con.prepareStatement(slowSql);
            ResultSet rs = st.executeQuery();
            rs.close();
            st.close();
        }
        System.out.println("Stats:"+stats);

        for (int i=0; i<count; i++) {
            CallableStatement st = con.prepareCall(slowSql);
            ResultSet rs = st.executeQuery();
            rs.close();
            st.close();
        }
        System.out.println("Stats:"+stats);
        assertEquals("Expecting to have received "+(2*count)+" notifications.",2*count, listener.notificationCount);
        con.close();
        tearDown();
        //make sure we actually did clean up when the pool closed
        assertNull(SlowQueryReport.getPoolStats(pool.getName()));
    }
View Full Code Here

            st.close();
        }
        Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
        assertNotNull(map);
        assertEquals(0,map.size());
        ConnectionPool pool = datasource.getPool();
        con.close();
        tearDown();
        assertNull(SlowQueryReport.getPoolStats(pool.getName()));
    }
View Full Code Here

        }
        Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
        assertNotNull(map);
        assertEquals(1,map.size());
        ConnectionPool pool = datasource.getPool();
        String key = map.keySet().iterator().next();
        SlowQueryReport.QueryStats stats = map.get(key);
        System.out.println("Stats:"+stats);
        con.close();
        tearDown();
        assertNull(SlowQueryReport.getPoolStats(pool.getName()));
    }
View Full Code Here

        prop.putAll(properties);
        updateProperties(prop, converted, null);

        final PoolConfiguration config = build(PoolProperties.class, converted);
        config.setDataSource(ds);
        final ConnectionPool pool;
        try {
            pool = new ConnectionPool(config);
        } catch (SQLException e) {
            throw new IllegalStateException(e);
        }
        return build(TomEEDataSource.class, new TomEEDataSource(config, pool, name), converted);
    }
View Full Code Here

TOP

Related Classes of org.apache.tomcat.jdbc.pool.ConnectionPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.