I have the following configuration in my standalone.xml :
<subsystem xmlns="urn:jboss:domain:datasources:1.1"> <datasources> <datasource jta="true" jndi-name="java:/jdbc/myds" pool-name="CADS" enabled="true" use-java-context="true" use-ccm="true"> <connection-url>jdbc:postgresql://db.host/name</connection-url> <driver>postgresql</driver> <new-connection-sql>select 1</new-connection-sql> <pool> <min-pool-size>20</min-pool-size> <max-pool-size>100</max-pool-size> <flush-strategy>IdleConnections</flush-strategy> </pool> <security> <user-name>user</user-name> <password>pwd</password> </security> <validation> <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/> <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/> </validation> <timeout> <blocking-timeout-millis>30000</blocking-timeout-millis> <idle-timeout-minutes>1</idle-timeout-minutes> </timeout> <statement> <track-statements>true</track-statements> </statement> </datasource> <drivers> <driver name="postgresql" module="org.postgresql"> <xa-datasource-class>org.postgresql.Driver</xa-datasource-class> </driver> </drivers> </datasources> </subsystem>
If for some reason the database stops responding for a second, JBoss cannot reconnect, and I have to restart the application server.
But, if I change the datasource to xa-datasource (keeping the configuration as it is in the example) using the org.postgresql.xa.PGXADataSource driver, it works .
Thing: I can’t understand from this. Correct me if I am wrong, but xa-datasources supposed to be used for synchronous committing in several databases, and this is not so. In fact, I have several databases configured, but I do not need to synchronize transactions between them.
The "default" datasource also seems to have problems setting up the connection pool. Sometimes, it doesn’t matter if the application loads, it opens more than 100 connections (even if the limit is 100) and closes them after a few seconds. This is hard to reproduce because it seems random, so I cannot say for sure that switching to xa-datasource also solves this problem.
Now:
- why switch to
xa-datasource ? - What are the consequences of this?
- Why is the connection pool going crazy?
To clarify, my test is as follows:
- run postgres and application server;
- Complete some application requests
- stop the database;
- Fulfill some requests to the application - and make sure that they do not work, because they cannot open any connections;
- start the database again;
- complete some application requests
At the last stage, xa-datasource can connect to postgres, and everything will work. datasource cannot and will not forever, download does not matter - I need to restart the application server.
source share