本文整理汇总了Java中org.apache.commons.pool2.impl.SoftReferenceObjectPool.borrowObject方法的典型用法代码示例。如果您正苦于以下问题:Java SoftReferenceObjectPool.borrowObject方法的具体用法?Java SoftReferenceObjectPool.borrowObject怎么用?Java SoftReferenceObjectPool.borrowObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.pool2.impl.SoftReferenceObjectPool
的用法示例。
在下文中一共展示了SoftReferenceObjectPool.borrowObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryWithResourcesReturnsSoftRefConnectionToPool
import org.apache.commons.pool2.impl.SoftReferenceObjectPool; //导入方法依赖的package包/类
@Test
public void tryWithResourcesReturnsSoftRefConnectionToPool() throws Exception {
SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
.createSoftReferenceObjectPool(() -> client.connect());
StatefulRedisConnection<String, String> usedConnection = null;
try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {
RedisCommands<String, String> sync = connection.sync();
sync.ping();
usedConnection = connection;
}
try {
usedConnection.isMulti();
fail("Missing RedisException");
} catch (RedisException e) {
assertThat(e).hasMessageContaining("deallocated");
}
pool.close();
}
示例2: softReferencePoolShouldWorkWithPlainConnections
import org.apache.commons.pool2.impl.SoftReferenceObjectPool; //导入方法依赖的package包/类
@Test
public void softReferencePoolShouldWorkWithPlainConnections() throws Exception {
SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
.createSoftReferenceObjectPool(() -> client.connect(), false);
borrowAndReturn(pool);
StatefulRedisConnection<String, String> connection = pool.borrowObject();
assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();
pool.returnObject(connection);
pool.close();
}
示例3: softRefPoolShouldWorkWithWrappedConnections
import org.apache.commons.pool2.impl.SoftReferenceObjectPool; //导入方法依赖的package包/类
@Test
public void softRefPoolShouldWorkWithWrappedConnections() throws Exception {
SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
.createSoftReferenceObjectPool(() -> client.connect());
StatefulRedisConnection<String, String> connection = pool.borrowObject();
assertThat(channels).hasSize(1);
RedisCommands<String, String> sync = connection.sync();
sync.ping();
sync.close();
pool.close();
Wait.untilTrue(channels::isEmpty).waitOrTimeout();
assertThat(channels).isEmpty();
}