Skip to content

Commit a7552be

Browse files
committed
Sort members
1 parent 28e7a79 commit a7552be

File tree

2 files changed

+119
-119
lines changed

2 files changed

+119
-119
lines changed

src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,20 @@ public final long getBorrowedCount() {
547547
return borrowedCount.get();
548548
}
549549

550+
/**
551+
* Gets whether detailed timing statistics collection is enabled.
552+
* When {@code false}, the pool will not collect detailed timing statistics for
553+
* mean active time, mean idle time, and mean borrow wait time,
554+
* improving performance under high load.
555+
*
556+
* @return {@code true} if detailed statistics collection is enabled,
557+
* {@code false} if disabled for improved performance.
558+
* @since 2.13.0
559+
*/
560+
public boolean getCollectDetailedStatistics() {
561+
return collectDetailedStatistics;
562+
}
563+
550564
/**
551565
* Gets the total number of objects created for this pool over the lifetime of
552566
* the pool.
@@ -871,20 +885,6 @@ public final long getMeanIdleTimeMillis() {
871885
return idleTimes.getMean();
872886
}
873887

874-
/**
875-
* Gets whether detailed timing statistics collection is enabled.
876-
* When {@code false}, the pool will not collect detailed timing statistics for
877-
* mean active time, mean idle time, and mean borrow wait time,
878-
* improving performance under high load.
879-
*
880-
* @return {@code true} if detailed statistics collection is enabled,
881-
* {@code false} if disabled for improved performance.
882-
* @since 2.13.0
883-
*/
884-
public boolean getCollectDetailedStatistics() {
885-
return collectDetailedStatistics;
886-
}
887-
888888
/**
889889
* Gets whether to include statistics in exception messages.
890890
* <p>
@@ -1385,6 +1385,21 @@ public final void setBlockWhenExhausted(final boolean blockWhenExhausted) {
13851385
this.blockWhenExhausted = blockWhenExhausted;
13861386
}
13871387

1388+
/**
1389+
* Sets whether detailed timing statistics collection is enabled.
1390+
* When {@code false}, the pool will not collect detailed timing statistics,
1391+
* improving performance under high load at the cost of reduced monitoring capabilities.
1392+
* <p>
1393+
* This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
1394+
* </p>
1395+
*
1396+
* @param collectDetailedStatistics whether to collect detailed statistics.
1397+
* @since 2.13.0
1398+
*/
1399+
public void setCollectDetailedStatistics(final boolean collectDetailedStatistics) {
1400+
this.collectDetailedStatistics = collectDetailedStatistics;
1401+
}
1402+
13881403
/**
13891404
* Sets the receiver with the given configuration.
13901405
*
@@ -1617,21 +1632,6 @@ public final void setMaxWaitMillis(final long maxWaitMillis) {
16171632
setMaxWait(Duration.ofMillis(maxWaitMillis));
16181633
}
16191634

1620-
/**
1621-
* Sets whether detailed timing statistics collection is enabled.
1622-
* When {@code false}, the pool will not collect detailed timing statistics,
1623-
* improving performance under high load at the cost of reduced monitoring capabilities.
1624-
* <p>
1625-
* This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
1626-
* </p>
1627-
*
1628-
* @param collectDetailedStatistics whether to collect detailed statistics.
1629-
* @since 2.13.0
1630-
*/
1631-
public void setCollectDetailedStatistics(final boolean collectDetailedStatistics) {
1632-
this.collectDetailedStatistics = collectDetailedStatistics;
1633-
}
1634-
16351635
/**
16361636
* Sets whether to include statistics in exception messages.
16371637
* <p>

src/test/java/org/apache/commons/pool2/impl/TestBaseGenericObjectPool.java

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -95,64 +95,6 @@ void testBorrowWaitStatisticsMax() {
9595
assertEquals(20, pool.getMaxBorrowWaitTimeMillis(), Double.MIN_VALUE);
9696
}
9797

98-
@Test
99-
void testEvictionTimerMultiplePools() throws InterruptedException {
100-
final AtomicIntegerFactory factory = new AtomicIntegerFactory();
101-
factory.setValidateLatency(50);
102-
try (GenericObjectPool<AtomicInteger> evictingPool = new GenericObjectPool<>(factory)) {
103-
evictingPool.setTimeBetweenEvictionRuns(Duration.ofMillis(100));
104-
evictingPool.setNumTestsPerEvictionRun(5);
105-
evictingPool.setTestWhileIdle(true);
106-
evictingPool.setMinEvictableIdleTime(Duration.ofMillis(50));
107-
for (int i = 0; i < 10; i++) {
108-
try {
109-
evictingPool.addObject();
110-
} catch (final Exception e) {
111-
e.printStackTrace();
112-
}
113-
}
114-
115-
for (int i = 0; i < 1000; i++) {
116-
try (GenericObjectPool<AtomicInteger> nonEvictingPool = new GenericObjectPool<>(factory)) {
117-
// empty
118-
}
119-
}
120-
121-
Thread.sleep(1000);
122-
assertEquals(0, evictingPool.getNumIdle());
123-
}
124-
}
125-
126-
/**
127-
* POOL-393
128-
* Tests JMX registration does not add too much latency to pool creation.
129-
*/
130-
@SuppressWarnings("resource") // pools closed in finally block
131-
@Test
132-
@Timeout(value = 10_000, unit = TimeUnit.MILLISECONDS)
133-
void testJMXRegistrationLatency() {
134-
final int numPools = 1000;
135-
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
136-
final ArrayList<GenericObjectPool<Waiter>> pools = new ArrayList<>();
137-
try {
138-
// final long startTime = System.currentTimeMillis();
139-
for (int i = 0; i < numPools; i++) {
140-
pools.add(new GenericObjectPool<>(new WaiterFactory<>(0, 0, 0, 0, 0, 0), new GenericObjectPoolConfig<>()));
141-
}
142-
// System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
143-
final ObjectName oname = pools.get(numPools - 1).getJmxName();
144-
assertEquals(1, mbs.queryNames(oname, null).size());
145-
} finally {
146-
pools.forEach(GenericObjectPool::close);
147-
}
148-
}
149-
150-
@Test
151-
void testCollectDetailedStatisticsDefault() {
152-
// Test that collectDetailedStatistics defaults to true for backward compatibility
153-
assertTrue(pool.getCollectDetailedStatistics());
154-
}
155-
15698
@Test
15799
void testCollectDetailedStatisticsConfiguration() {
158100
// Test configuration through config object
@@ -168,6 +110,12 @@ void testCollectDetailedStatisticsConfiguration() {
168110
assertTrue(pool.getCollectDetailedStatistics());
169111
}
170112

113+
@Test
114+
void testCollectDetailedStatisticsDefault() {
115+
// Test that collectDetailedStatistics defaults to true for backward compatibility
116+
assertTrue(pool.getCollectDetailedStatistics());
117+
}
118+
171119
@Test
172120
void testCollectDetailedStatisticsDisabled() throws Exception {
173121
// Configure pool to disable detailed statistics
@@ -229,6 +177,90 @@ void testCollectDetailedStatisticsToggling() throws Exception {
229177
assertEquals(2, pool.getReturnedCount());
230178
}
231179

180+
@Test
181+
void testDetailedStatisticsConfigIntegration() {
182+
// Test that config property is properly applied during pool construction
183+
final GenericObjectPoolConfig<String> config = new GenericObjectPoolConfig<>();
184+
config.setCollectDetailedStatistics(false);
185+
try (GenericObjectPool<String> testPool = new GenericObjectPool<>(factory, config)) {
186+
assertFalse(testPool.getCollectDetailedStatistics(), "Pool should respect collectDetailedStatistics setting from config");
187+
// Test that toString includes the new property
188+
final String configString = config.toString();
189+
assertTrue(configString.contains("collectDetailedStatistics"), "Config toString should include collectDetailedStatistics property");
190+
}
191+
}
192+
193+
@Test
194+
void testEvictionTimerMultiplePools() throws InterruptedException {
195+
final AtomicIntegerFactory factory = new AtomicIntegerFactory();
196+
factory.setValidateLatency(50);
197+
try (GenericObjectPool<AtomicInteger> evictingPool = new GenericObjectPool<>(factory)) {
198+
evictingPool.setTimeBetweenEvictionRuns(Duration.ofMillis(100));
199+
evictingPool.setNumTestsPerEvictionRun(5);
200+
evictingPool.setTestWhileIdle(true);
201+
evictingPool.setMinEvictableIdleTime(Duration.ofMillis(50));
202+
for (int i = 0; i < 10; i++) {
203+
try {
204+
evictingPool.addObject();
205+
} catch (final Exception e) {
206+
e.printStackTrace();
207+
}
208+
}
209+
210+
for (int i = 0; i < 1000; i++) {
211+
try (GenericObjectPool<AtomicInteger> nonEvictingPool = new GenericObjectPool<>(factory)) {
212+
// empty
213+
}
214+
}
215+
216+
Thread.sleep(1000);
217+
assertEquals(0, evictingPool.getNumIdle());
218+
}
219+
}
220+
221+
/**
222+
* POOL-393
223+
* Tests JMX registration does not add too much latency to pool creation.
224+
*/
225+
@SuppressWarnings("resource") // pools closed in finally block
226+
@Test
227+
@Timeout(value = 10_000, unit = TimeUnit.MILLISECONDS)
228+
void testJMXRegistrationLatency() {
229+
final int numPools = 1000;
230+
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
231+
final ArrayList<GenericObjectPool<Waiter>> pools = new ArrayList<>();
232+
try {
233+
// final long startTime = System.currentTimeMillis();
234+
for (int i = 0; i < numPools; i++) {
235+
pools.add(new GenericObjectPool<>(new WaiterFactory<>(0, 0, 0, 0, 0, 0), new GenericObjectPoolConfig<>()));
236+
}
237+
// System.out.println("Duration: " + (System.currentTimeMillis() - startTime));
238+
final ObjectName oname = pools.get(numPools - 1).getJmxName();
239+
assertEquals(1, mbs.queryNames(oname, null).size());
240+
} finally {
241+
pools.forEach(GenericObjectPool::close);
242+
}
243+
}
244+
245+
@Test
246+
void testStatsStoreCircularBuffer() throws Exception {
247+
// Test that StatsStore properly handles circular buffer behavior
248+
final DefaultPooledObject<String> pooledObject = (DefaultPooledObject<String>) factory.makeObject();
249+
// Fill beyond the cache size (100) to test circular behavior
250+
final int cacheSize = 100; // BaseGenericObjectPool.MEAN_TIMING_STATS_CACHE_SIZE
251+
for (int i = 0; i < cacheSize + 50; i++) {
252+
pool.updateStatsBorrow(pooledObject, Duration.ofMillis(i));
253+
pool.updateStatsReturn(Duration.ofMillis(i * 2));
254+
}
255+
// Statistics should still be meaningful after circular buffer wrapping
256+
assertTrue(pool.getMeanActiveTimeMillis() > 0);
257+
assertTrue(pool.getMeanBorrowWaitTimeMillis() > 0);
258+
assertTrue(pool.getMaxBorrowWaitTimeMillis() > 0);
259+
// The mean should reflect recent values, not all historical values
260+
// (exact assertion depends on circular buffer implementation)
261+
assertTrue(pool.getMeanBorrowWaitTimeMillis() >= 50); // Should be influenced by recent higher values
262+
}
263+
232264
@Test
233265
void testStatsStoreConcurrentAccess() throws Exception {
234266
// Test the lock-free StatsStore implementation under concurrent load
@@ -277,36 +309,4 @@ void testStatsStoreConcurrentAccess() throws Exception {
277309
executor.shutdown();
278310
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
279311
}
280-
281-
@Test
282-
void testStatsStoreCircularBuffer() throws Exception {
283-
// Test that StatsStore properly handles circular buffer behavior
284-
final DefaultPooledObject<String> pooledObject = (DefaultPooledObject<String>) factory.makeObject();
285-
// Fill beyond the cache size (100) to test circular behavior
286-
final int cacheSize = 100; // BaseGenericObjectPool.MEAN_TIMING_STATS_CACHE_SIZE
287-
for (int i = 0; i < cacheSize + 50; i++) {
288-
pool.updateStatsBorrow(pooledObject, Duration.ofMillis(i));
289-
pool.updateStatsReturn(Duration.ofMillis(i * 2));
290-
}
291-
// Statistics should still be meaningful after circular buffer wrapping
292-
assertTrue(pool.getMeanActiveTimeMillis() > 0);
293-
assertTrue(pool.getMeanBorrowWaitTimeMillis() > 0);
294-
assertTrue(pool.getMaxBorrowWaitTimeMillis() > 0);
295-
// The mean should reflect recent values, not all historical values
296-
// (exact assertion depends on circular buffer implementation)
297-
assertTrue(pool.getMeanBorrowWaitTimeMillis() >= 50); // Should be influenced by recent higher values
298-
}
299-
300-
@Test
301-
void testDetailedStatisticsConfigIntegration() {
302-
// Test that config property is properly applied during pool construction
303-
final GenericObjectPoolConfig<String> config = new GenericObjectPoolConfig<>();
304-
config.setCollectDetailedStatistics(false);
305-
try (GenericObjectPool<String> testPool = new GenericObjectPool<>(factory, config)) {
306-
assertFalse(testPool.getCollectDetailedStatistics(), "Pool should respect collectDetailedStatistics setting from config");
307-
// Test that toString includes the new property
308-
final String configString = config.toString();
309-
assertTrue(configString.contains("collectDetailedStatistics"), "Config toString should include collectDetailedStatistics property");
310-
}
311-
}
312312
}

0 commit comments

Comments
 (0)