I'm working on the project where I'm trying to get the runtime statistics of my datasource connection pool which I placed into /deployment folder using Wildfly-9.
I searched for it and I found the configuration file which exist inside /standalone folder named as standalone.xml file giving me the statistics of datasource connection poool by using below code :
<datasource jta="true" jndi-name="java:jboss/datasources/DemoDS" pool-name="DemoDS" enabled="true" use-ccm="true" statistics-enabled="true">
<connection-url>jdbc:mysql://localhost:3306/demo?zeroDateTimeBehavior=convertToNull</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
Hit this url I got this:
http://localhost:9990/management/subsystem/datasources/data-source/DemoDS/statistics/pool?include-runtime=true
I get the following json string:
You get the following json string:
{
"ActiveCount":4,
"AvailableCount":48,
"AverageBlockingTime":0,
"AverageCreationTime":21,
"AverageGetTime":17,
"AveragePoolTime":195196,
"AverageUsageTime":43,
"BlockingFailureCount":0,
"CreatedCount":4,
"DestroyedCount":0,
"IdleCount":2,
"InUseCount":2,
"MaxCreationTime":47,
"MaxGetTime":47,
"MaxPoolTime":386185,
"MaxUsageTime":134,
"MaxUsedCount":4,
"MaxWaitCount":0,
"MaxWaitTime":0,
"TimedOut":0,
"TotalBlockingTime":0,
"TotalCreationTime":87,
"TotalGetTime":88,
"TotalPoolTime":780787,
"TotalUsageTime":217,
"WaitCount":0,
"XACommitAverageTime":0,
"XACommitCount":0,
"XACommitMaxTime":0,
"XACommitTotalTime":0,
"XAEndAverageTime":0,
"XAEndCount":0,
"XAEndMaxTime":0,
"XAEndTotalTime":0,
"XAForgetAverageTime":0,
"XAForgetCount":0,
"XAForgetMaxTime":0,
"XAForgetTotalTime":0,
"XAPrepareAverageTime":0,
"XAPrepareCount":0,
"XAPrepareMaxTime":0,
"XAPrepareTotalTime":0,
"XARecoverAverageTime":0,
"XARecoverCount":0,
"XARecoverMaxTime":0,
"XARecoverTotalTime":0,
"XARollbackAverageTime":0,
"XARollbackCount":0,
"XARollbackMaxTime":0,
"XARollbackTotalTime":0,
"XAStartAverageTime":0,
"XAStartCount":0,
"XAStartMaxTime":0,
"XAStartTotalTime":0,
"statistics-enabled":true
}
Since I have many datasource file I cannot place into individual standalone.xml file.
So anyone knows how I will get the runtime statistics of my datasource connection pool which I placed into /deployment folder?
From Wildfly CLI:
Check if stats enabled for datasource
/subsystem=datasources/data-source=(your datasourcename):read-attribute(name=statistics-enabled)
Enable stats: requires restart of Wildfly service afterwards
/subsystem=datasources/data-source=(your datasource):write-attribute(name=statistics-enabled, value=true)
After restart start CLI and run the check command again.
I have deployed an EAR in Wildfly-8.2.0.Final application server. After some hours of inactivity, I am getting the below error:
Caused by: java.sql.SQLException - JZ0C0: Connection is already closed.
at com.sybase.jdbc4.jdbc.ErrorMessage.raiseError(Unknown Source)
at com.sybase.jdbc4.jdbc.SybConnection.checkConnection(Unknown Source)
at com.sybase.jdbc4.jdbc.SybConnection.setAutoCommit(Unknown Source)
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.checkTransaction(BaseWrapperManagedConnection.java:893)
at org.jboss.jca.adapters.jdbc.WrappedConnection.checkTransaction(WrappedConnection.java:1594)
at org.jboss.jca.adapters.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:398)
at com.test.it.TestConnection.prepareStatement(TestConnection.java:1045)
Please find below the datasource subsystem definition used in standalone-full-ha.xml.
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jta="true" jndi-name="java:/SybaseDB" pool-name="SybaseDB" enabled="true" use-java-context="true" spy="false" use-ccm="true">
<connection-url>jdbc:sybase:Tds:id_address:port/DBname</connection-url>
<driver-class>com.sybase.jdbc4.jdbc.SybDriver</driver-class>
<connection-property name="HOSTNAME">TestHost</connection-property>
<connection-property name="SQLINITSTRING">set quoted_identifier,forceplan off</connection-property>
<connection-property name="LANGUAGE">us_english</connection-property>
<connection-property name="CHARSET">iso_1</connection-property>
<connection-property name="APPLICATIONNAME">TestApp</connection-property>
<connection-property name="IS_CLOSED_TEST">select 1</connection-property>
<connection-property name="PACKETSIZE">1024</connection-property>
<driver>SybaseDB</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<initial-pool-size>5</initial-pool-size>
<max-pool-size>200</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<security-domain>EncryptDBPassword</security-domain>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<use-fast-fail>true</use-fast-fail>
</validation>
<timeout>
<blocking-timeout-millis>15000</blocking-timeout-millis>
<idle-timeout-minutes>30</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>false</track-statements>
</statement>
</datasource>
<drivers>
<driver name="SybaseDB" module="jdbc.jconn4"/>
</drivers>
</datasources>
</subsystem>
Could anyone please help me whether I am missing an attribute in datasource definition which gives me this error.
I am using multiple datasources in my java web-application.
Here is Wildfly configuration (standalone mode):
<datasource jta="false" jndi-name="java:jboss/datasources/DS1" pool-name="DS1" enabled="true" use-ccm="false">
<connection-url>URL1</connection-url>
<driver>ojdbc7</driver>
<security>
<user-name>login</user-name>
<password>password</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<datasource jta="false" jndi-name="java:jboss/datasources/DS2" pool-name="DS2" enabled="true" use-ccm="false">
<connection-url>URL2</connection-url>
<driver-class>org.h2.Driver</driver-class>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
Jboss.xml in my ejb subproject:
<session>
<ejb-name>Bean1</ejb-name>
<resource-description>
<res-ref-name>DS1</res-ref-name>
<jndi-name>java:jboss/datasources/DS1</jndi-name>
</resource-description>
</session>
<session>
<ejb-name>Bean2</ejb-name>
<resource-description>
<res-ref-name>DS2</res-ref-name>
<jndi-name>java:jboss/datasources/DS2</jndi-name>
</resource-description>
</session>
In EJB Bean1/Bean2 datasources are called via
#Resource(name="DS1/DS2")
private DataSource dataSource;
....
Connection connection = dataSource.getConnection();
Using shown configuration I have faced following problems :
I can access datasource only if it is set as a default in <default-bindings> section of my standalone-full.xml. If it is empty, I get
"JBAS014771: Services with missing/unavailable dependencies"
pointing to the list of datasources used in beans during deployment.
If I set DS1 as a default one, next time DS2 is injected, it will contain
LocalManagedConnectionFactory
pointing to DS1 in dataSource.mcf variable
As I've understood from this topic
Why different persistence units with separated data sources query the same data source?
this problem may be caused by container-managed persistance.
But in given case I am not using any ORM. So I am only able to manipulate datasources using jndi and server configuration.
So is there any way I can resolve this situation by using some additional wildfly configuration / any manipulations with application or I have to use ORM and manage persistance by myself ?
Thanks for replies.
it's recommended to use an ORM (JPA in best case), so you will use entityManager and persitence.xml for using multiple data sources.
<persistence-unit name="DB1_PU">
<jta-data-source>java:jboss/datasources/ds1</jta-data-source>
</persistence-unit>
<persistence-unit name="DB2_PU">
<jta-data-source>java:jboss/datasources/ds2</jta-data-source>
</persistence-unit>
and you can call the DS like :
#PersistenceContext(unitName = "DB1_PU")
protected EntityManager entityManager1;
#PersistenceContext(unitName = "DB2_PU")
protected EntityManager entityManager2;
How to configure a JNDI datasource in jboss configuration file using HikariCP I can't find aything in the help contents of Hikari there is only Tomcat configuration .
I have a Spring webb app, I have a datasource defined inside the application and I want to move this to a JNDI datasource.
My datasource definition is:
<datasource jndi-name="java:jboss/datasources/mydatasource" pool-name="mydatasource" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost:5432/database</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<datasource-class>com.zaxxer.hikari.HikariDataSource</datasource-class>
<driver>postgresql</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>10</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
And the driver definition:
<driver name="postgresql" module="org.postgresql.jdbc">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
I'm getting this error among others:
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "mydatasource")
]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/mydatasource is missing [jboss.jdbc-driver.postgresql]",
"jboss.data-source.java:jboss/datasources/mydatasource is missing [jboss.jdbc-driver.postgresql]"
]}
So what is the right way to configure this?
EDIT:
Following the guide to create the Tomcat resource and using the information provided in this question I have come to this DataSource definition:
<datasource jta="false" jndi-name="java:jboss/mydatasource" pool-name="mydatasource" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/databasename</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>10</max-pool-size>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
I installed the postgresql driver in Jboss and declared it.
And in Spring configuration
...
#Bean
public DataSource dataSource() {
final JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
dataSourceLookup.setResourceRef(true);
DataSource dataSourceTemp = null;
try {
dataSourceTemp = dataSourceLookup.getDataSource("jdbc/mydatasource");
} catch (DataSourceLookupFailureException e) {
log.error("DataSource not found.");
}
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDataSource(dataSourceTemp);
return new HikariDataSource(hikariConfig);
}
...
This code based on HikariJNDIFactory code,everything seems to work but I think I have to create a properties object with the properties of the connection what properties I have to include in the object?
Here is the configuration for a "pure" Tomcat JNDI DataSource:
https://github.com/brettwooldridge/HikariCP/wiki/JNDI-DataSource-Factory-(Tomcat,-etc.)
You might also find this answer Re: Spring + Tomcat + JNDI informative:
How to use JNDI DataSource provided by Tomcat in Spring?
Also recommended is the latest HikariCP 2.0.1.
I have this datasource configuration on my JBOSS AS 7 in standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/MyJndiDS" pool-name="MyPoolDS" enabled="true" jta="true" use-java-context="false" use-ccm="true">
<connection-url>
jdbc:postgresql://192.168.2.125:5432/t_report
</connection-url>
<driver>
org.postgresql
</driver>
<transaction-isolation>
TRANSACTION_READ_COMMITTED
</transaction-isolation>
<pool>
<min-pool-size>
3
</min-pool-size>
<max-pool-size>
7
</max-pool-size>
<prefill>
true
</prefill>
<use-strict-min>
false
</use-strict-min>
<flush-strategy>
FailingConnectionOnly
</flush-strategy>
</pool>
<security>
<user-name>
my_user
</user-name>
<password>
my_pass
</password>
</security>
<statement>
<prepared-statement-cache-size>
32
</prepared-statement-cache-size>
</statement>
</datasource>
...
...
</datasources>
</subsystem>
And when I login and logout 7 times with one and the same user the next time i try to login I get Transaction not active error. How can I fix this? I don't want to increase the max-pool-size. Here is my logout method:
import javax.faces.context.ExternalContext;
#Inject ExternalContext ec;
public void validateUserLogOut() {
HttpServletRequest request = (HttpServletRequest)ec.getRequest();
request.getSession().invalidate();
this.setUserLoggedIn(false);
navigation.logout();
}
I think your issue is less the datasource (this only exposes it), but rather the fact that the login module seems to keep connections open and is not returning them into the pool.
Due to request of user503413 I will admit the mistake I've made with a disgrace: I have forgotten to close the connection after using it (connection.close()). If you don't close your connection it will not return it to the pool and since you've limited and reached the max-pool-size (7 in my case) no new connection is going to be created. So the lesson here is always be sure to close your connections. Also close your prepared statements or else you'll get a memory leak.