Package org.apache.tomcat.jdbc.pool

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


            super(poolProperties);
        }

        @Override
        public ConnectionPool createPool() throws SQLException {
            ConnectionPool pool = super.createPool();
            registerJmxLazily(pool);
            return pool;
        }
View Full Code Here


    return dataSource.getPool();
  }

  @Override
  public void addMetrics(MetricTreeObject tree) {
    ConnectionPool pool = getPool();
    if (pool == null) {
      // TODO: Should we handle this properly??
      return;
    }

    MetricTreeObject subtree = tree.getSubtree(key);

    // Statistics stats = pool.getStatistics();
    // subtree.addInt("hitCount", stats.getCacheHits());
    // subtree.addInt("missCount", stats.getCacheMiss());
    // subtree.addInt("connectionsRequested", stats.getConnectionsRequested());
    // subtree.addInt("statementsCached", stats.getStatementsCached());
    // subtree.addInt("statementsExecuted", stats.getStatementsExecuted());
    // subtree.addInt("statementsPrepared", stats.getStatementsPrepared());
    // subtree.addInt("cumulativeConnectionWaitTime", stats.getCumulativeConnectionWaitTime());
    // subtree.addInt("cumulativeStatementExecutionTime", stats.getCumulativeStatementExecutionTime());
    // subtree.addInt("cumulativeStatementPrepareTime", stats.getCumulativeStatementPrepareTime());
    //
    subtree.addInt("activeConnections", pool.getActive());
    subtree.addInt("idleConnections", pool.getIdle());
    subtree.addInt("waitCount", pool.getWaitCount());

  }
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

        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

        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 (final 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

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

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.