I have some applications running on JBoss 4.2.2, JBoss 5.1 and WildFly 8.1.0. All these applications use connection pooling. My datasources are something like that:
<datasource jta="false" jndi-name="java:/datasource/myawesomeds" pool-name="MyAwesomeDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#myserver.example.com:1521:oracle_service</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>ojdbc6.jar</driver>
<security>
<user-name>username</user-name>
<password>MyPassWord</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>
As you can see, I use Oracle Database. The server version is 10g. When Oracle DB going down for a few minutes all my applications on JBoss and WildFly start showing SQLException: Closed Connection.
My question: Is it normal? Why JBoss and WildFly don't check the connections to verify this?
Yes, this is normal.
You can however define that wildfly/jboss should verify the connection when fetching it from the connection pool. All your connections will be invalid, so normally it should create a new connection for you if you defined a minimum number of connections that should be present.
Related
Inside my host.xml file, I have the following entry:
<servers>
<server name="server-one" group="application-group" auto-start="true">
<socket-bindings socket-binding-group="full-sockets" port-offset="1"/>
</server>
<server name="server-two" group="application-group" auto-start="true">
<socket-bindings socket-binding-group="full-sockets" port-offset="2"/>
</server>
</servers>
In the domain.xml, I have data source configured like this:
<datasource jta="true" jndi-name="java:/myApp" pool-name="java:/myApp" enabled="true" use-ccm="true">
<connection-url>some_url</connection-url>
<driver>ojdbc6.jar</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>50</max-pool-size>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
</datasource>
Since the max pool size is specified at 50, does it mean that its the max pool 50 per server (specified in host.xml) or its the overall pool size shared by all servers?
The pool configurations are copied to each JVM(server).
Servers cannot share a single physical pool of connections.
If a pool has a max-pool-size of 50, this value should be multiplied by the number of JVMs using the profile (include all JVMs using the profile on all hosts). According to your example, the potential number of open connections could reach 50*2 (depending on usage).
I am trying to get to the underlaying Oracle connection in my WebApp on a JBoss Wildly 8.1 server.
I get an exception when I try to do the unwrap:
connection.unwrap(OracleConnection.class);
Throws
java.sql.SQLException: Not a wrapper for: oracle.jdbc.OracleConnection
The connection's class turns out to be com.sun.proxy.$Proxy37
This is my configuration in standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/myds" pool-name="MyPool" enabled="true">
<connection-url>jdbc:oracle:thin:#//host:152x/blabla</connection-url>
<driver>Oracle11g</driver>
<security>
<user-name>xxx</user-name>
<password>yyy</password>
</security>
</datasource>
<drivers>
<driver name="Oracle11g" module="com.oracle.ojdbc6">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
How can I get to the OracleConnection?
Edit: I have configured the oracle driver in the standalone.xml and the driver is added in the modules folder. In order to be able to get my code compiled, I have added a dependency in my pom-file to the driver as well. No idea if this is part of the cause.
Thanks
I found the solution!
When using this statement I can get to the OracleConnection object:
(oracle.jdbc.driver.OracleConnection) conn.getMetaData().getConnection();
So I have a servlet where I login to a database with Datasource(where I only pass the JNDI name) with a default schema(which was set in the JBoss management console) but later on I need to connect on the same database with another schema in order to get some texts.
How does JBoss manage this ? Can I provide the later schema and password somehow in the java code ?
În standalone.xml you declare all your datasources. Those connections can be picked up by jndi at runtime by looking up on an InitialContext instance.
When using JNDI to form connections, you will need to configure the new datasource within the management console or the standalone.xml file. This will simply be a new datasource, with a connection URL going to the same database, but pointing to a new schema.
Example output in the standalone.xml:
<datasource jta="false" jndi-name="java:/firstDS" pool-name="firstDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#devdb:1521:SCHEMA_1</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
...
<datasource jta="false" jndi-name="java:/secondDS" pool-name="secondDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#devdb:1521:SCHEMA_2</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
Now in the second part of your application you will just refer to that second datasource's JNDI name when forming the connection.
I developed an application which is currently running on Jboss with JNDI, but I'd like to run it on Tomcat with minimal reconfiguration by user who will be given .WAR file.
Is this possible, and how?
Jboss 7.1.3
Tomcat 7.0
EDIT:
This is a part of a code I'm using currently with Jboss:
<%#page import="java.sql.*"%>
Connection conn = null;
Context initialContext = new InitialContext();
String DATASOURCE_CONTEXT = initialContext.lookup("java:comp/env/dbJNDIds").toString();
DataSource datasource = (DataSource) initialContext.lookup(DATASOURCE_CONTEXT);
conn = datasource.getConnection();
This is the JNDI definition in standalone.xml:
<xa-datasource jta="true" jndi-name="java:jboss/datasources/MyDatasource" pool-name="MyDatasource" enabled="true" use-java-context="true" use-ccm="true">
<xa-datasource-property name="URL">
jdbc:sqlserver://localhost;database=MyDatabase;sendStringParametersAsUnicode=false;username=sa;password=sa
</xa-datasource-property>
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
<driver>sqljdbc</driver>
<xa-pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>1000</max-pool-size>
<prefill>true</prefill>
<is-same-rm-override>false</is-same-rm-override>
</xa-pool>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
</validation>
</xa-datasource>
This is the JNDI reference in web.xml (for Jboss):
<env-entry>
<env-entry-name>dbJNDIds</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>java:jboss/datasources/MyDatasource</env-entry-value>
</env-entry>
So, I'd like to add web.xml JNDI definition "dbJNDIds" (on which I reference in .JSP) that will work on Tomcat along with current Jboss configuration, so I don't have to recompile different version of a project just for Tomcat etc.
Also, it would be nice to see some other possibilities, like for Glassfish...
:D Hi there
I have installed jboss-as-7.1.1.Final for my webapp.
Its running normally for every activity except one thing.
When ms sql server services was restarted or stopped a while, my jboss wouldn't rebuild the connection to datasource automatically.
I must restarting jboss manually, so it can rebuild the connection again.
What i want is jboss autoreconnecting when that problem happen again.
Below is my datacource config, could you tell me please what i am miss?
....
<datasource jndi-name="java:jboss/MsSqlDS" pool-name="MsSqlDS" enabled="true" use-java-context="true" use-ccm="false">
<connection-url>jdbc:sqlserver://localhost:1433;databaseName=dummy</connection-url>
<driver>sqlserver2008</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>sa</user-name>
<password>*******</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
</validation>
</datasource>
....
note :
i have try this
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</validation>
based on Is there any way to have the JBoss connection pool reconnect to Oracle when connections go bad?
but still not work for me
Thanks & Regards
Newbie