0

How can I change from shared connections( which is by default) to unshared connection. ?

And how to ensure if the connection to data source which I m using is unshared?

androidDev
  • 1,179
  • 4
  • 13
  • 31

1 Answers1

0

You need to define resource reference, either via annotation or deployment descriptor for example:

Annotation:

@Resource(shareable=false)
DataSource datasource;

Deployment descriptor:

  <resource-ref>
    <res-ref-name>jdbc/mydbdatasourceRef</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Unshareable</res-sharing-scope>
  </resource-ref>

And if you use deployment descriptor make sure that lookup is via reference - java:comp/env/jdbc/mydbdatasourceRef - not the global jndi name.

UPDATE

You dont need to set defaultConnectionTypeOverride or globalConnectionTypeOverride, they allow you to set sharing without references, or override references.

defaultConnectionTypeOverride - The defaultConnectionTypeOverride property changes the default sharing value for a connection pool. This property enables you to control connection sharing for direct look-ups. If resource references are configured for a data source or connection factory they take precedence over this property and the resource reference settings are used.

globalConnectionTypeOverride - The value specified for the globalConnectionTypeOverride custom property takes precedence over all of the other connection sharing settings. For example, if you set this property to unshared, all connection requests are unshared for both direct look-ups and resource reference lookups.

For more details check Connection pool custom properties in the Knowledge Center.

Gas
  • 17,601
  • 4
  • 46
  • 93
  • Gas.... do we also need to set two custom properties in Connection pool in data source; globalConnectionTypeOverride and defaultConnectionTypeOverride? – androidDev Aug 27 '15 at 02:21