WebSphere local transaction containment boundary issue J2CA0086W - jdbc

In WebSphere, if you code opens two concurrent database connections, you get an error of the form:
J2CA0086W: Shareable connection MCWrapper id 556e556e Managed connection WSRdbManagedConnectionImpl#52365236 State:STATE_TRAN_WRAPPER_INUSE
from resource jdbc/abc was used within a local transaction containment boundary.
Our framework allows us to do so (nested transactions which can be on a separate connection or multiple named transactions). I've seen lots of references to turning off some switch in WebSphere to turn on connection sharing but no details on how to set this flag. Can someone point me to the steps to achieve this?
Specifically, if you see this article: http://www-01.ibm.com/support/docview.wss?rs=180&context=SSEQTP&dc=DB520&dc=D600&dc=DB530&dc=D700&dc=DB500&dc=DB540&dc=DB510&dc=DB550&q1=j2ca0086w&uid=swg21121449&loc=en_US&cs=utf-8&lang=en
under "Resolving the problem" I want to know how to set the connection pool to be unshareable (assuming that indeed solves the problem).

What version of IBM WAS are you using? If you have WAS 8, go to
Resources-> JDC-> Datasources-> your datasources -> WebSphere Application Server properties -> Datasources no transactional.
Sorry for my english.

The message happens when dataSource.getConnection() is called twice in
a servlet. The datasource jdbc/oracle is lookup from local reference.
Call it once and reuse the connection or call con.close() before doing the 2nd getConnection()

Related

Firebird JDBC connection pool validation on Payara server

After a Firebird database crash the connections of the JDBC pool become invalid. (We have to flush the pool manually.) A good concept might be to use jdbc connection pool validation.
Connection validation properties
I am not sure what is the validation classname of the payara implementation, or in general what configuration works here. Is there a better way to handle the problem?
Thanks to Mark Rotteveel I have solved the problem. Also thanks for pointing out the importance of the jaybird driver upgrade. I used the following asadmin commands:
set resources.jdbc-connection-pool.jdbc_pool_name.connection-validation-method=custom-validation
set resources.jdbc-connection-pool.jdbc_pool_name.validation-classname=org.glassfish.api.jdbc.validation.JDBC40ConnectionValidation
set resources.jdbc-connection-pool.jdbc_pool_name.is-connection-validation-required=true
set resources.jdbc-connection-pool.jdbc_pool_name.fail-all-connections=true
In my case the main cause of the error was a Firebird segfault. The configurations above have passed the tests.

What do the following Spring datasource properties mean?

I have come across some datasource properties for Spring Boot, that are specified in the application.properties. I am having a hard time understanding the purpose of the datasource properties.
Also, I am not able to find the explanation of these properties here for datasource - https://docs.spring.io/spring-boot/docs/1.1.2.RELEASE/reference/html/common-application-properties.html and I am using Spring Boot version 1.
spring.datasource.test-while-idle=true
spring.datasource.initial-size=10
spring.datasource.min-idle=10
spring.datasource.time-between-eviction-runs-millis=300000
spring.datasource.validation-query=SELECT 1 from DUAL
spring.datasource.test-on-borrow=true
spring.datasource.test-on-connect=true
spring.datasource.validation-interval=300000
The properties are validation-interval and time-between-eviction-runs-millis. What is the difference between them? The latter runs to evict the dead connections. But what about validation-interval?
Difference between test-on-borrow and test-on-connect?
I can't seem to find the right place to see their documentation or their purpose, or I am looking at the wrong place.
Please advise.
Following explanation is based on my experience, for your reference.
spring.datasource.time-between-eviction-runs-millis means the time interval to recycle idle connection. It is usually used with spring.datasource.test-while-idle.
spring.datasource.min-evictable-idle-time-millis means the effective time of idle connection in connection pool.
spring.datasource.test-on-borrow means whether testing the connection while borrowing the connection from connection pool. And it may have some impact on the performance.
spring.datasource.test-on-connect means whether testing the connection while creating the connection.

WSO2 Identity Server - Custom JDBC User Store Manager - JDBC Pools

WSO2 Identity Server 5.0.0 (and some patches ;))
It does not appear that custom JDBC user store managers (child of JDBCUserStoreManager) use a JDBC pool. I'm noticing that I can end up session closed errors and sql exceptions whereas the Identity Server itself is still operating OK with its separate database connection (a configured pool).
So I guess I have two questions about this:
Somewhere up the chain, is there a JDBC pool for the JDBCUserStoreManager? If so, are there means to configure that guy more robustly?
Can I create another JDBC datasource in master-datasources.xml which my custom JDBC user store manage could reference?
Instead of using your own datasources/connections, you can import Carbon Datasources and use those (they come with inbuilt pooling and no need to worry about any configurations etc). You can either access these programmatically by directly calling ndatasource component or access them via JNDI.
To access them directly from ndatasource component:
The dependency:
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
<version>add_correct_version_here</version>
</dependency>
(You can check repository/components/plugins to find out the correct version for above dependency)
You can inject DataSourceService as in this code (the #scr.reference tag refers to the service you need to inject, this uses maven scr plugin to parse these dependencies when building the bundle).
Note that when you follow this approach you'll have to build the jar as an OSGi bundle as it uses declarative services (and have to place it in repository/components/dropins). Otherwise the dependencies won't be injected at runtime.
Next, you can access all the data sources as:
List<CarbonDataSource> dataSources = dataSourceService.getAllDataSources();
Rajeev's answer was really insightful and helped with investigating and evaluating what I should do. But, I didn't end up using that route. :)
I ended up looking through the Identity Server and Carbon source code and found out that the JDBCUserStoreManager does end up creating a JDBC pool configured by the properties you set for that manager. I had a class called CustomUserStoreConstants for my custom user store manager which had setMandatoryProperty called by default to set:
JDBCRealmConstants.DRIVER_NAME
JDBCRealmConstants.URL
JDBCRealmConstants.USER_NAME
JDBCRealmConstants.PASSWORD
So the pool was configured with these values, BUT that was it...nothing else. So no wonder it wasn't surviving the night!
It turned out that the code setting this up, if it found a value for the JDBCRealmConstants.DATASOURCE in the config params, it would just load up that datasource and ignore any other params set. Seeing that, I got rid of those 4 params listed above and forced my custom user store to only allow having a DATASOURCE and I set it in code with the default JNDI name that I would name that datasource always. With that, I was able to configure my JDBC pool for this datasource with all params such as testOnBorrow, validationQuery, validationInterval, etc in master-datasources.xml. Now the only thing that would ever need to change is the datasource's configuration in that file.
The other reason I went with the datasource in the master-datasources.xml is that I didn't have to decided in my custom user store's code which parameters I would want to have or not have and just manage it all in the xml file easily. This really has advantages with portability of configs and IT involvement for deployments and debugging. I already have other datasources in this file for the IS deployment.
All said, my user store is now living through the night and weekends. :)

Maintaining multiple connection pools with spring/eclipse link

we use spring and eclipse link (using the eclipse link connection pool)
We'd like to allocate two connection pools- the default should be used normally, the second should be used for transactional methods that requires a new transaction (#Transactional(propagation = Propagation.REQUIRES_NEW))
is it possible?
thanks..

Tomcat Connection Pool Concept & c3p0 connection pooling?

I have two Java Web Applications running under Tomcat (6.0) and using the Tomcat & c3p0 connection pool as Tomcat Data-source.If I define two Resources (server.xml) for two different Oracle Connection and use c3p0 for connection pool as below which my we applications use, my questions are:
<Resource
name="jdbc/OracleDB"
auth="Container"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
driverClass="oracle.jdbc.OracleDriver"
factory="xxx"
jdbcUrl="jdbc:oracle:thin:#(DESCRIPTION= (LOAD_BALANCE=on)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx) (PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xxx)))"
maxPoolSize="10"
minPoolSize="0"
maxIdleTime="60"
maxConnectionAge="600"
acquireIncrement="1"
user="xxx="
password="xxx=" />
<Resource name="jdbc/xxx2DB"
auth="Container"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
driverClass="oracle.jdbc.OracleDriver"
factory="xxx"
jdbcUrl="jdbc:oracle:thin:#xxx:1527:xxx"
maxPoolSize="10"
minPoolSize="0"
acquireIncrement="1"
maxIdleTime="60"
maxConnectionAge="600"
user="xxx"
password="xxx"
/>
Q1. Does the below in server.xml mean that two connection pools are existing in the Tomcat
memory to two different Oracle Instances?
Q2. Do I have to specify any configuration properties (ref:http://www.mchange.com/projects/c3p0/index.html#configuration_properties) , in my case I have a connection to an Oracle RAC instance and another to a single instance of Oracle. Should I take into account
any additional configuration properties in an enterprise environment ?
Q3. Are the below setting valid enough?
Q4. How do I enable c3p0 logging (i have only the jar in Tomcat lib and the above setting for now?
Any advice?
Thanks in advance.
A1: Yes.
A2: Not sure if I got the question right, but you should only specify those connection properties which defaults do not make sense to you. It's probably best to do this in the separate c3p0.properties file and specify which connection which property applies to. Answer to 'additional configuration properties' question requires to know the specifics of your environment. I would recommend looking at idle_test_period setting as these can typically have wrong defaults (make sure this matches relevant setting on the DB end).
A3: Yeah, this looks OK.
A4: You need to specify logging preferences in c3p0.properties or define them in dynamically as System properties. Refer to this chapter of the c3p0 manual.
A1: Yes
A2: Looks right at first glance. You need to be careful with RAC in case you would use distributed transactions - then I believe you would have to specify additional properties.
A3: Looks ok but depending on your task and estimated load I would play with maxIdleTime, acquireIncrement and maxPoolSize. For example with current settings after 60 seconds of inactivity your connection will be closed so next operation requesting connection after 60 seconds would incur penalty in waiting for new connection to open.
A4: http://www.mchange.com/projects/c3p0/index.html#configuring_logging
Advice:
There is a better connection pool from Tomcat 7, which could be used in Tomcat 6 as well. Consider it, especially if you need high performance
Consider connection testing so your application don't get (or get less frequently) exception when db connectivity goes down
It might be preferable to package connection pool and it's configuration within your application vs. in Tomcat. This way application WAR would be self contained so it could be just dropped into wabapps dir of tomcat.

Resources