You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2019/03/27 19:51:00 UTC

[jira] [Work logged] (POOL-363) Evictor Thread prevents Spring Context shutdown in standalone app

     [ https://issues.apache.org/jira/browse/POOL-363?focusedWorklogId=219558&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-219558 ]

ASF GitHub Bot logged work on POOL-363:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Mar/19 19:50
            Start Date: 27/Mar/19 19:50
    Worklog Time Spent: 10m 
      Work Description: joshlandin commented on pull request #20: Fix for POOL-363
URL: https://github.com/apache/commons-pool/pull/20
 
 
   Updated evictor thread to be a daemon, thus no longer blocking
   application hooks (added via Runtime.addShutdownHook) and causing the VM
   to hang on shutdown. For example, stand-alone applications using the
   Spring Framework.
 
----------------------------------------------------------------
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


Issue Time Tracking
-------------------

            Worklog Id:     (was: 219558)
            Time Spent: 10m
    Remaining Estimate: 0h

> Evictor Thread prevents Spring Context shutdown in standalone app
> -----------------------------------------------------------------
>
>                 Key: POOL-363
>                 URL: https://issues.apache.org/jira/browse/POOL-363
>             Project: Commons Pool
>          Issue Type: Bug
>    Affects Versions: 2.4.3, 2.5.0, 2.6.0, 2.6.1
>         Environment: Java {{1.8.0_92}}
>            Reporter: Josh Landin
>            Priority: Major
>         Attachments: 2019.03.26_screen281.jpg
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Given a DBCP2 connection pool configured in a Spring Application context with the POOL evictor thread enabled, a standalone main() application hangs on shutdown. Example below:
> Maven pom.xml:
> {code:xml}
>   <dependencies>
>     <dependency>
>       <groupId>org.apache.commons</groupId>
>       <artifactId>commons-dbcp2</artifactId>
>       <version>2.6.0</version><!-- Uses commons-pool2 : 2.6.1 -->
>     </dependency>
>     <dependency>
>       <groupId>mysql</groupId>
>       <artifactId>mysql-connector-java</artifactId>
>       <version>8.0.15</version>
>     </dependency>
>     <dependency>
>       <groupId>org.springframework</groupId>
>       <artifactId>spring-context</artifactId>
>       <version>5.1.5.RELEASE</version>
>     </dependency>
>   </dependencies>
> {code}
> MainTest.java:
> {code:java}
> import java.sql.Connection;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
> import javax.sql.DataSource;
> import org.apache.commons.dbcp2.BasicDataSource;
> import org.springframework.context.annotation.AnnotationConfigApplicationContext;
> import org.springframework.context.annotation.Bean;
> import org.springframework.context.annotation.Configuration;
> public class MainTest
> {
>   @Configuration
>   public static class Config 
>   {
>     @Bean
>     public DataSource getBasicDataSource()
>     {
>       BasicDataSource d = new BasicDataSource();
>       d.setUrl("jdbc:mysql://localhost:3306/anydb");
>       d.setUsername("myuser");
>       d.setPassword("mypass");
>       d.setTimeBetweenEvictionRunsMillis(1000); // Turn on Evictor Thread.
>       return d;
>     }
>   }
>   public static void main(String[] args)
>   {
>     AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
>     ctx.registerShutdownHook(); // Ensures context.close() on JVM shutdown.
>     
>     try(
>         Connection conn = ctx.getBean(BasicDataSource.class).getConnection(); 
>         Statement stmt = conn.createStatement();
>         ResultSet result = stmt.executeQuery("SELECT 1");
>     )
>     {
>       int records = result.last() ? result.getRow() : 0;
>       System.out.println("Records: "+records);
>     }
>     catch(SQLException e)
>     {
>       e.printStackTrace();
>     }
>     System.out.println("End.");
>   }
> }
> {code}
> The issue is not present when turning off the eviction thread by setting {{timeBetweenEvictionRunsMillis}} to {{-1}}.
> Jconsole thread summary attached for reference.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)