Wednesday Dec 23, 2009

Ping Connection Pool


While a JDBC/Connector Connection pool is created, there was no way of identifying the erroneous values for some of the attributes. With the introduction of a new attribute "ping" in GlassFish V3, its possible to do so. 

An incorrect value of a database connectivity property is another case where pooling infrastructure does not warn the user when pool is created or reconfigured.

For example, if a user tries to set a wrong value for isolation level during creation like :


asadmin create–jdbc–connection–pool ........ ––isolationlevel xyz poolName

The erroneous isolation level is identified only at runtime when the pool is initialized. A get connection from an application following this would throw a WARNING message. This can be identified at an earlier stage by setting a flag like

asadmin create–jdbc–connection–pool ........ ––isolationlevel xyz --ping=true poolName

The default value of this flag is false.

CLI

Ping CLI attribute

GUI

Ping admin console

Notes

The Ping button in admin console as well as the admin CLI command asadmin ping-connection-pool are still supported in GlassFish V3.

[1] Ping CLI Command

Tuesday Dec 22, 2009

Disable Connection Pooling

Connection pooling allows you to reuse connections from a pool
instead of creating a new connection object everytime. If you desire to
turn off the connection pooling in GlassFish V3, there is a new
attribute that could be used.

By default, connection pooling is enabled in both jdbc as well as
connector connection pools. To disable this, set the "pooling" attribute to false.

In the earlier releases of GlassFish, there was a system property called "com.sun.enterprise.Connectors.SwitchoffACCConnectionPooling"
that could be set to true to turn off connection pooling in application
clients. This property is still supported in the new GlassFish V3.

How to set the flag

In administration CLI, use the following :

asadmin set server.resources.jdbc-connection-pool.
           ‹CONNECTION_POOL_NAME›.pooling=false

In admin GUI http://localhost:4848, see the Pooling checkbox.


Pooling in Admin Console

Effects observed

  • Associate with thread functionality is invalid

  • Flush connection pool cannot be done

Attributes useful only in pooled environment

There are a few attributes that are useful only in pooled environment hence a WARNING message is seen in the server.log when they are used.


  • Connection validation

  • Validate Atmost Once (Related to Connection Validation)

  • Match Connections

  • Max Connection Usage

  • Idle Timeout

Wednesday Dec 16, 2009

JDBC in GlassFish V3

GlassFish V3, the first application server in the world that supports JavaEE6  is released !!!! For the JDBC users, there are some great features introduced in the newest version of GlassFish.


New features


Flush Connection Pool

To reinitialize aged/old connections in a connection pool. There is no need to reconfigure the pool to kill/destroy live connections.

Ping

The existing Ping button in admin console and asadmin ping-connection-pool reveal the unsupported values of configured attributes of a connection pool only at the time of usage (or runtime). A pool configured with "ping" attribute identifies erroneous values at the time of creation of the pool.

java.sql.Driver based Pooling Support

Mainly for applications that use java.sql.Driver  implementations, to configure non-compliant jdbc drivers.

Disable Pooling

Disable connection pooling by just setting a flag "pooling" to false. The existing system property com.sun.enterprise.connectors.SwitchoffACCConnectionPooling was useful only for application clients. This feature is for the non appclient pools.

Statement Caching

Cache Statement, PreparedStatement, CallableStatement objects executed repeatedly by applications to improve performance. Some JDBC drivers do not support caching and this feature comes in handy.

Custom Validation

Specify your own implementation for performing a connection validation. A custom implementation could be made available to the application server and used to perform validation when connection validation is turned ON. Validation routines could be performance oriented or database specific.

Init SQL

Execute a SQL query during connection creation. Mainly to set request/session specific properties.

Introspection of JDBC Drivers

A really useful feature that introspects and lists datasource/driver classnames based on the database vendor and resource type in the administration console. User does not need to remember the classnames anymore for a strange uncommon JDBC driver used with GlassFish.

Tracing SQL Statements

Trace SQL statements executed by your application using a jdbc connection pool. Administrators can filter the server.log for easier SQL statement analyses.


What has changed in GlassFish V3



  • Connection validation method has been defaulted to "table" as the auto–commit and meta–data values are cached by most of the JDBC drivers

  • GlassFish V3 pooling infrastructure will provide wrapped objects for Statement, Prepared/Callable Statement, ResultSet and DatabaseMetaData by default


    • wrap–jdbc–objects defaulted to true


Highlights

  • Monitoring support is provided in GlassFish V3 for JDBC using the new probe provider framework.

  • Smart admin GUI for JDBC leading to easier user administration


    • ex: listing of connection validation table names by introspection

    • ex: listing of jdbc classnames for a particular vendor


More on the above topics (new features) are coming soon. Watch out!

Flush Connection Pool

Re-initialize connections established in the pool without reconfiguration? – Flush Connection Pool is the solution.

This is a new feature in the latest GlassFish V3 that works to recreate the connections in the jdbc connection pool and brings the pool back to the steady pool size. Administrator's work is simplified by just executing the command (CLI) or pressing the Flush button in the GUI.

Effects


  • Live connections are killed/destroyed

  • Existing transactions are lost & hence should be retired

  • Pool brought to steady pool size after flush

Example

max-pool-size set to 5
steady-pool-size set to 5 (5 connections are initialized in the pool when it is created)

We would verify how Flush works based on physical connection IDs

An application that uses the jdbc resource of this connection pool gets 4 connections and closes them everytime in a loop. In this process, the logical connections are closed and returned back to the pool. The physical connection handles [1] for these 4 connections would be the same.

When a Flush is executed after this, the 5 connections that are in the pool are killed and recreated. When a 5th connection is got from the pool, the physical connection handle would be different.

How-Tos

Flush connection pool can be invoked in multiple ways :



Admin Console Flush


Some of the WARNING messages you might encounter when database server is not up or pool is not initialized and Flush is invoked :





References

[1] Obtain physical connection from a Wrapped connection

Tuesday Dec 15, 2009

Custom Validation in GlassFish V3

Connection Validation mechanism in GlassFish has been extended to provide a new type of validation mechanism – Custom Validation. Users can provide their own implementation to validate a connection during each application request.

During times when database server is restarted or a network failure, connections could become stale in the connection pool. When such connections are used by the applications, exceptions are thrown that connection got is invalid. There are types of connection validation mechanisms already existent in GlassFish : autocommit, metadata and table.

The connection-validation-method attribute can be set to custom-validation. This validation mechanism could could aid users to implement faster validation routines. If connection validation fails, pooling infrastructure will return the next valid connection or create a new connection to return to the application.

GlassFish provides a public interface org.glassfish.api.jdbc.ConnectionValidation for the users to implement and provide value to an attribute validation-classname.

Setting Custom Validation

Turn on Validation, set validation type to custom-validation and set an appropriate implementation class with the entire package name to validation-classname.


Turn on validation


Set to custom-validation


Set validation classname

In Admin console (http://localhost:4848) Connection validation settings can be made in the advanced tab.

Custom Validation mechanisms in GF

There are some default validation mechanisms provided by GlassFish for the users to use for certain databases. These are listed in the admin console against the validation classname field.


  • org.glassfish.api.jdbc.validation.DerbyConnectionValidation

  • org.glassfish.api.jdbc.validation.MySQLConnectionValidation

  • org.glassfish.api.jdbc.validation.PostgresConnectionValidation

  • org.glassfish.api.jdbc.validation.OracleConnectionValidation


There is also a generic validation implementation provided for jdbc 4.0 compliant drivers


  • org.glassfish.api.jdbc.validation.JDBC40ConnectionValidation

References

[1] Connection Validation in GlassFish

Thursday Nov 06, 2008

JDBC support in V3 Prelude


The latest application server of Sun – GlassFish V3 Prelude includes JDBC support. The JDBC Connection pooling infrastructure in V3 prelude is same as that of GlassFish 9.1 application server.


Some of the cool features that could be useful to you are :



  • Connection Leak Tracing


    •  enable the connection-leak-timeout to a certain value along with connection-leak-reclaim to true to avoid the potential connection leaks in your application


  • Validation calls optimization


    • Set the validate atmost once period to a value within which the validation will be carried out atmost once.


  • Associate with thread


    • To reuse connections in a multi threaded application to avoid the overhead of getting a connection from the pool.



and many more...


Things that have changed:


Setting the pool properties/attributes using asadmin set command would be like:


asadmin set --value=10 server.resources.jdbc-connection-pool.DerbyPool.steady-pool-size



asadmin set --value=newUser server.resources.jdbc-connection-pool.DerbyPool.property.User



Note that the first asadmin set does not need a server restart whereas the second one mandates restart.



There are many more attractive things coming up in the next release of V3 for JDBC. One of them is advanced pool monitoring. The monitoring framework has undergone a major change in v3 prelude.


Try the latest V3 prelude and its connection pooling features. Any issues? Mail users-AT-glassfish.dev.java-DOT-net .

Friday May 16, 2008

GlassFish V3 - Using JDBC Connection Pool / JDBC Resource / MySQL


This blog talks about creating a JDBC Connection Pool and an associated JDBC resource with MySQL as the Database vendor.


The
default database "sakila" of MySQL is used in this example. All these
could be done so easily with Netbeans 6.1 after installing the
GlassFish V3 plugin. 


This screencast explains how to create a JDBC Connection pool in the
administration console and its associated JDBC resource. It also shows
a HelloWorld web application that used this resource to get some values
from a table in sakila database.

Watch the screencast :


GlassFish V3 TP2 JDBC


Download GlassFish V3 TP2 from https://glassfish.dev.java.net/downloads/v3-techPreview-2.html

About

shalini_m

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today