简体   繁体   English

JBoss AS / Wildfly中的多用户数据库连接池

[英]Multiple users database connection pooling in JBoss AS/Wildfly

I'm working on web application, that need access to postgresql database. 我正在开发Web应用程序,需要访问postgresql数据库。

For some reason, i need to establish individual connection, for every authenticated user. 出于某种原因,我需要为每个经过身份验证的用户建立单独的连接。

My current datasource setup looks like this: 我当前的数据源设置如下所示:

<datasource jndi-name="java:jboss/ds" pool-name="ds-pool" enabled="true">
                    <connection-url>jdbc:postgresql://192.168.1.2:5432/springdb</connection-url>
                    <driver>postgresql-driver</driver>
                    <pool>
                        <min-pool-size>5</min-pool-size>
                        <max-pool-size>30</max-pool-size>                       
                    </pool>
                    <security>
                        <user-name>postgres</user-name>
                        <password>postgres</password>
                    </security>
                </datasource>

In java code i do this: 在java代码中我这样做:

@Resource(lookup = "java:jboss/ds")
DataSource ds;
conn = ds.getConnection(username, password);

And here is the problem. 这就是问题所在。 Every getConnection call produce following WARN in jboss console: 每个getConnection调用在jboss控制台中产生以下WARN:

> 14:07:48,665 WARN 
> [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (default
> task-11) IJ000612: Destroying connection that could not be
> successfully matched:
> org.jboss.jca.core.connectionmanager.listener.TxConnectionListener@7de0e076[state=NORMAL
> managed
> connection=org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@763ace0a
> connection handles=0 lastUse=1382422068665 trackByTx=false
> pool=org.jboss.jca.core.connectionmanager.pool.strategy.OnePool@36c78449
> mcp=SemaphoreArrayListManagedConnectionPool@64bdf0b7[pool=ds-pool]
> xaResource=LocalXAResourceImpl@ead2f2a[connectionListener=7de0e076
> connectionManager=26e60dae warned=false currentXid=null
> productName=PostgreSQL productVersion=9.3.3 jndiName=java:jboss/ds]
> txSync=null]

I've tried to add allow-multiple-users to pool configuration, but in jboss 7 i'm getting xml parse error, and in wildfly 8 it does nothing. 我试图将allow-multiple-users添加到配置中,但是在jboss 7中我得到xml解析错误,而在wildfly 8中它什么也没做。

So is there any way to get multiple users connection pool in jboss? 那么有没有办法在jboss中获得多个用户连接池?

It seems that I figured it out. 好像我想出来了。 So to enable multiple users in a connection pool, you need to add the following in the datasource definition: 因此,要在连接池中启用多个用户,需要在数据源定义中添加以下内容:

<allow-multiple-users>true</allow-multiple-users>

instead of: 代替:

<allow-multiple-users/>

Wildfly 8.0.0 Wildfly 8.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM