spring boot atomikos pool用尽了

时间:2017-11-08 13:38:55

标签: java spring-boot jdbc transactions atomikos

我想在REST服务中使用普通JDBC,但不会将连接返回到池。

使用下面的代码,第二个请求将以池耗尽结束。当我删除'@Transactional' - 它有效 - 但它没有事务,所以没有提交。

有什么遗漏的建议吗?

这些是Maven依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jta-atomikos</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

这是REST控制器:

@RestController
@RequestMapping(value = "/demo")
@RequestScoped
public class Controller {

    @Autowired
    @Qualifier("IMSDB")
    DataSource imsdb;

    @Autowired
    @Qualifier("SQLDB")
    DataSource sqldb;

    @RequestMapping("")
    @Transactional
    public String index() throws SQLException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
        Connection icon = imsdb.getConnection();

        Statement s = icon.createStatement();
        s.execute("select 1 from sysibm.sysdummy1");
        s.close();

        Connection con = sqldb.getConnection();

        Statement s2 = con.createStatement();
        s2.execute("select 1 from sysibm.sysdummy1");
        s2.close();

        icon.close();
        con.close();
        return "dd";
    }
}

0 个答案:

没有答案