Error accessing PooledConnection. Connection is invalid

3673 단어
    public static void main(String[] args) {
        final CountDownLatch latch = new CountDownLatch(1);
        final int threadCount = 10;

        for (int i = 0; i < threadCount; i++) {
            new Thread() {

                @Override
                public void run() {
                    try {
                        // all thread to wait
                        latch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    // do something
                    task();
                }
            }.start();
        }
        // release lock, let all thread excute at the same time
        latch.countDown();
    }

    private static void task() {
        SqlSession session = Singleton.INSTANCE.getMybatisFactory().openSession();
        try {
            InfoMapper mapper = session.getMapper(InfoMapper.class);
                        
            mapper.getNews(1);

            PageHelper.startPage(1, 10);
            mapper.listIndustryClass();
        } finally {
            session.close();
        }
    }

병렬 테스트를 실행하고, 10개의 라인을 아래와 같은 오류를 보고합니다.
### Cause: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy20.listIndustryClass(Unknown Source)
at jinxiu_m.Test.task(Test.java:66)
at jinxiu_m.Test.access$0(Test.java:58)
at jinxiu_m.Test$1.run(Test.java:47)
Caused by: java.sql.SQLException: Error accessing PooledConnection. Connection is invalid.
at org.apache.ibatis.datasource.pooled.PooledConnection.checkConnection(PooledConnection.java:254)
at org.apache.ibatis.datasource.pooled.PooledConnection.invoke(PooledConnection.java:243)
at com.sun.proxy.$Proxy21.prepareStatement(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:87)
at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:112)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy19.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
... 8 more

하면, 만약, 만약...
        PageHelper.startPage(1, 10);
        mapper.listIndustryClass();

        mapper.getNews(1);

혹은
//          mapper.getNews(1);
        
        PageHelper.startPage(1, 10);
        mapper.listIndustryClass();

잘못 보고하지 않을 것입니다. 원인은 조사를 기다리고 있습니다.

좋은 웹페이지 즐겨찾기