當前位置: 首頁>>代碼示例>>Java>>正文


Java BasePooledObjectFactory類代碼示例

本文整理匯總了Java中org.apache.commons.pool2.BasePooledObjectFactory的典型用法代碼示例。如果您正苦於以下問題:Java BasePooledObjectFactory類的具體用法?Java BasePooledObjectFactory怎麽用?Java BasePooledObjectFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BasePooledObjectFactory類屬於org.apache.commons.pool2包,在下文中一共展示了BasePooledObjectFactory類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupObjectPool

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
@Override
public void setupObjectPool() {
    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(poolSize);

    objectPool = new GenericObjectPool<>(new BasePooledObjectFactory<TestObject>() {
        @Override
        public TestObject create() throws Exception {
            return new TestObject(true);
        }

        @Override
        public PooledObject<TestObject> wrap(TestObject testObject) {
            return new DefaultPooledObject<>(testObject);
        }
    }, config);
}
 
開發者ID:chrishantha,項目名稱:microbenchmarks,代碼行數:18,代碼來源:CommonsPool2GenericObjectPoolBenchmark.java

示例2: setupObjectPool

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
@Override
public void setupObjectPool() {
    objectPool = new SoftReferenceObjectPool<>(new BasePooledObjectFactory<TestObject>() {
        @Override
        public TestObject create() throws Exception {
            return new TestObject(true);
        }

        @Override
        public PooledObject<TestObject> wrap(TestObject testObject) {
            return new DefaultPooledObject<>(testObject);
        }
    });
}
 
開發者ID:chrishantha,項目名稱:microbenchmarks,代碼行數:15,代碼來源:CommonsPool2SoftReferenceObjectPoolBenchmark.java

示例3: messagePoolFactory

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
private BasePooledObjectFactory<PollableChannel> messagePoolFactory() {
    return new BasePooledObjectFactory<PollableChannel>() {
            @Override
            public PollableChannel create()
                throws Exception {
                return new QueueChannel(10);
            }

            @Override
            public PooledObject<PollableChannel> wrap(PollableChannel obj) {
                return new DefaultPooledObject<PollableChannel>(obj);
            }
        };
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:15,代碼來源:ConversationConfiguration.java

示例4: OperativeFactoryImpl

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
/**
 * Creates a new OperativeFactoryImpl object.
 *
 * @param activeOperativePoolFactory .
 */
public OperativeFactoryImpl(BasePooledObjectFactory<Operative> activeOperativePoolFactory,
    BasePooledObjectFactory<Operative> passiveOperativePoolFactory) {
    if (activeOperativePoolFactory != null) {
        activeOperativePool = new GenericObjectPool<Operative>(activeOperativePoolFactory);
    }

    if (passiveOperativePoolFactory != null) {
        passiveOperativePool = new GenericObjectPool<Operative>(passiveOperativePoolFactory);
    }
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:16,代碼來源:OperativeFactoryImpl.java

示例5: createBasePooledObjectfactory

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
private BasePooledObjectFactory<String> createBasePooledObjectfactory() {
	return new BasePooledObjectFactory<String>() {
		@Override
		public String create() {
			// fake
			return null;
		}

		@Override
		public PooledObject<String> wrap(final String obj) {
			// fake
			return null;
		}
	};
}
 
開發者ID:apache,項目名稱:commons-pool,代碼行數:16,代碼來源:TestGenericObjectPool.java

示例6: PooledSphinxDataSource

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
public PooledSphinxDataSource(BasePooledObjectFactory<SphinxClient> factory) {
    this(new GenericObjectPool<SphinxClient>(factory));
}
 
開發者ID:bcowdery,項目名稱:sphinx-api-pool,代碼行數:4,代碼來源:PooledSphinxDataSource.java

示例7: JdbcConnectionPoolDemo

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
public JdbcConnectionPoolDemo() {

            initPool(new PoolConfig(), new BasePooledObjectFactory<Connection>() {

                @Override
                public Connection create() throws Exception {

                    return null;
                }

                @Override
                public PooledObject<Connection> wrap(Connection obj) {

                    return null;
                }

            });

        }
 
開發者ID:DarkPhoenixs,項目名稱:connection-pool-client,代碼行數:20,代碼來源:JdbcConnectionPoolTest.java

示例8: testEvictionSoftMinIdle

import org.apache.commons.pool2.BasePooledObjectFactory; //導入依賴的package包/類
@Test(timeout=60000)
public void testEvictionSoftMinIdle() throws Exception {
    class TimeTest extends BasePooledObjectFactory<TimeTest> {
        private final long createTime;

        public TimeTest() {
            createTime = System.currentTimeMillis();
        }

        @Override
        public TimeTest create() throws Exception {
            return new TimeTest();
        }

        @Override
        public PooledObject<TimeTest> wrap(final TimeTest value) {
            return new DefaultPooledObject<>(value);
        }

        public long getCreateTime() {
            return createTime;
        }
    }

    try (final GenericObjectPool<TimeTest> timePool = new GenericObjectPool<>(new TimeTest())) {

        timePool.setMaxIdle(5);
        timePool.setMaxTotal(5);
        timePool.setNumTestsPerEvictionRun(5);
        timePool.setMinEvictableIdleTimeMillis(3000L);
        timePool.setSoftMinEvictableIdleTimeMillis(1000L);
        timePool.setMinIdle(2);

        final TimeTest[] active = new TimeTest[5];
        final Long[] creationTime = new Long[5];
        for (int i = 0; i < 5; i++) {
            active[i] = timePool.borrowObject();
            creationTime[i] = Long.valueOf((active[i]).getCreateTime());
        }

        for (int i = 0; i < 5; i++) {
            timePool.returnObject(active[i]);
        }

        // Soft evict all but minIdle(2)
        Thread.sleep(1500L);
        timePool.evict();
        assertEquals("Idle count different than expected.", 2, timePool.getNumIdle());

        // Hard evict the rest.
        Thread.sleep(2000L);
        timePool.evict();
        assertEquals("Idle count different than expected.", 0, timePool.getNumIdle());
    }
}
 
開發者ID:apache,項目名稱:commons-pool,代碼行數:56,代碼來源:TestGenericObjectPool.java


注:本文中的org.apache.commons.pool2.BasePooledObjectFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。