当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionPool类代码示例

本文整理汇总了Java中org.apache.tomcat.jdbc.pool.ConnectionPool的典型用法代码示例。如果您正苦于以下问题:Java ConnectionPool类的具体用法?Java ConnectionPool怎么用?Java ConnectionPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionPool类属于org.apache.tomcat.jdbc.pool包,在下文中一共展示了ConnectionPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: disconnected

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Override
public void disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) {
    @SuppressWarnings("unchecked")
    ConcurrentHashMap<CacheKey,CachedStatement> statements =
        (ConcurrentHashMap<CacheKey,CachedStatement>)con.getAttributes().get(STATEMENT_CACHE_ATTR);

    if (statements!=null) {
        for (Map.Entry<CacheKey, CachedStatement> p : statements.entrySet()) {
            closeStatement(p.getValue());
        }
        statements.clear();
    }

    super.disconnected(parent, con, finalizing);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:StatementCache.java

示例2: poolStarted

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void poolStarted(ConnectionPool pool) {
    super.poolStarted(pool);
    //see if we already created a map for this pool
    queries = SlowQueryReport.perPoolStats.get(pool.getName());
    if (queries==null) {
        //create the map to hold our stats
        //however TODO we need to improve the eviction
        //selection
        queries = new ConcurrentHashMap<String,QueryStats>();
        if (perPoolStats.putIfAbsent(pool.getName(), queries)!=null) {
            //there already was one
            queries = SlowQueryReport.perPoolStats.get(pool.getName());
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:20,代码来源:SlowQueryReport.java

示例3: testFastSql

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Test
public void testFastSql() throws Exception {
    int count = 3;
    this.init();
    this.datasource.setMaxActive(1);
    this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
    Connection con = this.datasource.getConnection();
    String fastSql = this.datasource.getValidationQuery();
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(fastSql);
        rs.close();
        st.close();
    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(0,map.size());
    ConnectionPool pool = datasource.getPool();
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:TestSlowQueryReport.java

示例4: testPoolCleaner

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Test
public void testPoolCleaner() throws Exception {
    datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
    datasource.getPoolProperties().setTestWhileIdle(true);
    Assert.assertEquals("Pool cleaner should not be started yet.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present.",0, countPoolCleanerThreads());

    datasource.getConnection().close();
    Assert.assertEquals("Pool cleaner should have 1 cleaner.",1,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should be 1.",1, countPoolCleanerThreads());

    datasource.close();
    Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());


}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:PoolCleanerTest.java

示例5: test2PoolCleaners

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Test
public void test2PoolCleaners() throws Exception {
    datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
    datasource.getPoolProperties().setTestWhileIdle(true);

    DataSource ds2 = new DataSource(datasource.getPoolProperties());

    Assert.assertEquals("Pool cleaner should not be started yet.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present.",0, countPoolCleanerThreads());

    datasource.getConnection().close();
    ds2.getConnection().close();
    Assert.assertEquals("Pool cleaner should have 2 cleaner.",2,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should be 1.",1, countPoolCleanerThreads());

    datasource.close();
    Assert.assertEquals("Pool cleaner should have 1 cleaner.",1,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());

    ds2.close();
    Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
    Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
    Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:27,代码来源:PoolCleanerTest.java

示例6: setUp

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    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);

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:JmxPasswordTest.java

示例7: createPool

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public synchronized ConnectionPool createPool() throws SQLException {
    if (pool == null) { // is first pool initialization
        try {
            // super.start() will call createPool() method, so we must initialize pool first
            // to ensure single initialization and not run into recursive loop.
            ConnectionPool connectionPool = super.createPool();
            if (connectionPool == null) {
                // sanity check. must never happen, but taken into account all variety of jdbc providers...
                return null;
            }
            super.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return super.createPool();
}
 
开发者ID:cvent,项目名称:dropwizard-mybatis,代码行数:20,代码来源:LazyManagedPooledDataSource.java

示例8: reset

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con)
{
    trackedConnPool = parent;
    trackedPooledCon = con;

    if (parent != null && con != null)
    {
        ConnPair cp = new ConnPair();
        cp.conn = con;
        cp.thread = Thread.currentThread();
        Set<ConnPair> pairs = conns.get(parent);
        if (pairs != null)
        {
            conns.get(parent).add(cp);
        }
    }
}
 
开发者ID:enioka,项目名称:jqm,代码行数:19,代码来源:PayloadInterceptor.java

示例9: forceCleanup

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
/**
 * Called by the engine to trigger the cleanup at the end of a payload thread.
 */
public static int forceCleanup(Thread t)
{
    int i = 0;
    for (Map.Entry<ConnectionPool, Set<ConnPair>> e : conns.entrySet())
    {
        for (ConnPair c : e.getValue())
        {
            if (c.thread.equals(t))
            {
                try
                {
                    // This will in turn remove it from the static Map.
                    c.conn.getHandler().invoke(c.conn, Connection.class.getMethod("close"), null);
                }
                catch (Throwable e1)
                {
                    e1.printStackTrace();
                }
                i++;
            }
        }
    }
    return i;
}
 
开发者ID:enioka,项目名称:jqm,代码行数:28,代码来源:PayloadInterceptor.java

示例10: poolStarted

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void poolStarted(ConnectionPool pool) {
    super.poolStarted(pool);
    //see if we already created a map for this pool
    queries = SlowQueryReport.perPoolStats.get(pool.getName());
    if (queries==null) {
        //create the map to hold our stats
        //however TODO we need to improve the eviction
        //selection
        queries = new ConcurrentHashMap<String,QueryStats>() {
            
        };
        if (perPoolStats.putIfAbsent(pool.getName(), queries)!=null) {
            //there already was one
            queries = SlowQueryReport.perPoolStats.get(pool.getName());
        }
    }
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:22,代码来源:SlowQueryReport.java

示例11: testFastSql

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
public void testFastSql() throws Exception {
    int count = 3;
    this.init();
    this.datasource.setMaxActive(1);
    this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
    Connection con = this.datasource.getConnection();
    String fastSql = this.datasource.getValidationQuery();
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(fastSql);
        rs.close();
        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()));
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:22,代码来源:TestSlowQueryReport.java

示例12: setUp

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    this.datasource.setPassword(password);
    this.datasource.setUsername(username);
    this.datasource.getConnection().close();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    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);
    
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:20,代码来源:JmxPasswordTest.java

示例13: reset

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
    super.reset(parent, con);
    if (parent!=null) {
        poolName = parent.getName();
        pool = parent;
        registerJmx();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:10,代码来源:SlowQueryReportJmx.java

示例14: reset

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
    super.reset(parent, con);
    if (parent==null) {
        cacheSize = null;
        this.pcon = null;
    } else {
        cacheSize = cacheSizeMap.get(parent);
        this.pcon = con;
        if (!pcon.getAttributes().containsKey(STATEMENT_CACHE_ATTR)) {
            ConcurrentHashMap<CacheKey,CachedStatement> cache = new ConcurrentHashMap<CacheKey, CachedStatement>();
            pcon.getAttributes().put(STATEMENT_CACHE_ATTR,cache);
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:StatementCache.java

示例15: reset

import org.apache.tomcat.jdbc.pool.ConnectionPool; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
    super.reset(parent, con);
    if (parent!=null)
        queries = SlowQueryReport.perPoolStats.get(parent.getName());
    else
        queries = null;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:9,代码来源:SlowQueryReport.java


注:本文中的org.apache.tomcat.jdbc.pool.ConnectionPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。