You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/05/25 06:33:27 UTC
[GitHub] [commons-dbcp] kyohei-nakamura commented on a change in pull request #40: Add Evictor threads test code.
kyohei-nakamura commented on a change in pull request #40:
URL: https://github.com/apache/commons-dbcp/pull/40#discussion_r429753652
##########
File path: src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java
##########
@@ -916,6 +917,34 @@ public void testCreateConnectionFactory() throws Exception {
conn.close();
ds.close();
}
+
+ @Test
+ public void testEvict() throws Exception {
+ ds.setInitialSize(10);
+ ds.setMaxIdle(10);
+ ds.setMaxTotal(10);
+ ds.setMinIdle(5);
+ ds.setNumTestsPerEvictionRun(3);
+ ds.setMinEvictableIdleTimeMillis(100);
+ ds.setTimeBetweenEvictionRunsMillis(1000);
+ ds.setPoolPreparedStatements(true);
+
+ Connection conn = ds.getConnection();
+ conn.close();
+
+ ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
+ while (Arrays.stream(threadBean.getThreadInfo(threadBean.getAllThreadIds()))
+ .anyMatch(t -> t.getThreadName().equals("commons-pool-evictor-thread"))) {
+ if (ds.getNumIdle() <= ds.getMinIdle()) {
+ break;
+ }
+ Thread.sleep(1000);
Review comment:
Thanks for your comment.
The Evictor thread runs with a delay of the value of timeBetweenEvictionRunsMillis.
I think that the sleep time of the main thread should refer to that value.
I have fixed it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org