Multiple users database connection pooling in JBoss AS/Wildfly

connection-pooling, datasource, java, jboss

Solution

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

Problem

I'm working on web application, that need access to postgresql database. 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: ``` @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: ``` > 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. So is there any way to get multiple users connection pool in jboss?

Original source