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.
Related
I am facing issue on looking up a local (oracle) data source configured in JBOSS EAP 7.1.4 version.
The Data source is configured properly and I am able to test the connection successfully from the console. However I am not able to lookup/get the connection using the datsource
Standalone.xml entries
<datasource jndi-name="java:jboss/jdbc/TEST_DS" pool-name="TEST_DS" use-java-context="false">
<connection-url>jdbc:oracle:thin:#//XXX.XX.XX.XX:1521/DES</connection-url>
<driver>OracleDriver</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>80</max-pool-size>
</pool>
<security>
<user-name>User</user-name>
<password>pass</password>
</security>
</datasource>
<drivers>
<driver name="OracleDriver" module="com.oracle.jdbc">
<driver-class>oracle.jdbc.OracleDriver</driver-class>
</driver>
</drivers>
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<lookup name="java:/jdbc/TEST_DS" lookup="java:jboss/jdbc/TEST_DS"/>
</bindings>
<remote-naming/>
</subsystem>
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
env.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS","JBOSS-LOCAL-USER");
env.put(Context.PROVIDER_URL, "remote+http://localhost:8080");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
InitialContextic = new InitialContext(env);
DataSource ds = (DataSource) ic.lookup("TEST_DS");
Connection con = ds.getConnection();
I am getting javax.naming.NameNotFoundException
I have tried options with
"/env/jdbc/TEST_DS"
"jdbc/TEST_DS"
"/jdbc/TEST_DS"
"jdbc/TEST_DS"
"java:jboss/jdbc/TEST_DS"
I am new to Jboss.. What am I doing wrong?
I have upgraded sybase data base driver from jconn3.jar to jconn4.jar in my project. I get the below error when my application connects to Sybase data source. I have deployed my application on JBOSS 7 server.
[org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory] (default task-48) IJ030027: Destroying connection that is not valid, due to the following exception: com.sybase.jdbc4.jdbc.SybConnection#36d4f39c: com.sybase.jdbc4.jdbc.SybSQLException: dual not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
at com.sybase.jdbc4.tds.Tds.processEed(Tds.java:4131)
at com.sybase.jdbc4.tds.Tds.nextResult(Tds.java:3247)
at com.sybase.jdbc4.jdbc.ResultGetter.nextResult(ResultGetter.java:78)
at com.sybase.jdbc4.jdbc.SybStatement.nextResult(SybStatement.java:294)
at com.sybase.jdbc4.jdbc.SybStatement.nextResult(SybStatement.java:276)
at com.sybase.jdbc4.jdbc.SybStatement.executeLoop(SybStatement.java:2828)
at com.sybase.jdbc4.jdbc.SybStatement.execute(SybStatement.java:2815)
at com.sybase.jdbc4.jdbc.SybStatement.execute(SybStatement.java:1447)
at org.jboss.jca.adapters.jdbc.CheckValidConnectionSQL.isValidConnection(CheckValidConnectionSQL.java:74)
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory.isValidConnection(BaseWrapperManagedConnectionFactory.java:1272)
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnectionFactory.getInvalidConnections(BaseWrapperManagedConnectionFactory.java:1085)
What does 'dual not found' in the error mean?
Can you please let me know what is the root cause of this issue and help to resolve it?
My data source configuration is shown below :
<datasource jta="false" jndi-name="java:/SybaseDS" pool-name="SybaseDS" enabled="true" use-ccm="false">
<connection-url>*********************</connection-url>
<driver-class>com.sybase.jdbc4.jdbc.SybDriver</driver-class>
<driver>sybase</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
</pool>
<validation>
<check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.sybase.SybaseExceptionSorter"/>
</validation>
<timeout>
<set-tx-query-timeout>false</set-tx-query-timeout>
<blocking-timeout-millis>0</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
<use-try-lock>0</use-try-lock>
<allocation-retry>0</allocation-retry>
<allocation-retry-wait-millis>0</allocation-retry-wait-millis>
</timeout>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
I will resolved this issue by removing the connection validation query in the data source as shown below :
<check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
The dual table doesn't exist in Sybase database.
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.