Troubleshooting
Problem
SQLj applications must close SQLj Connection Context to avoid violation of the WebSphere programming model.
Cause
Not closing the SQLj Connection Context will result in the finalizer method of the SQLj Connection Context Object being run by the GC (Garbage Collector). Part of the SQLj Connection Context finalizer method is to close the SQLj Connection Context underlying Objects (for example: prepared statements, connections, profiles, and so on). The fact that the closure happens by the GC on the finalizer thread, results in violation of the WebSphere programming model as multiple threads are accessing the same WebSphere JDBC Object (the normal thread, and the finalizer thread). The violation can result in a range of issues. One possible issue can be identified from the following message found in the WebSphere Application Server trace:
WSJdbcPrepare 1 Already closed. |
java.lang.IndexOutOfBoundsException. |
Resolving The Problem
There are two ways to resolve the issue:
- The application must close the SQLj Connection Context when done using it. Close the context with the CLOSE_CONNECTION option (or without any parameter, which means the same thing) if you will no longer be using the connection handle. Close the context with the KEEP_CONNECTION option if you intend to continue using the connection handle, in which case you are responsible for closing the connection handle once you are done with it. Failure to do so might result in a connection leak.
For example:
If your context ismyContext
and your connection iscon
, then the code would be:
- The SQLj must be translated using the -db2optimize option and sqlj customization must be run on the SQLj profiles. Doing that will result in DB2 creating a default Context under the covers that is cached inside of WebSphere Application Server. Note that this option will also provide better performance due to the caching of Connection Context.
myContext.close( ConnectionContext.CLOSE_CONNECTION); |
or myContext.close(ConnectionContext.KEEP_CONNECTION); //...continue using the connection con.close(); |
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21251464