IBM Support

SQLj Applications must close Connection Context after usage

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.

A more severe exception would be the following:

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 is myContext and your connection is con, then the code would be:

  • myContext.close(ConnectionContext.CLOSE_CONNECTION);


    or


    myContext.close(ConnectionContext.KEEP_CONNECTION);
    //...continue using the connection
    con.close();


  • 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.

[{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"DB Connections\/Connection Pooling","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.0;7.0;6.1;6.0","Edition":"Base;Network Deployment","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSNVBF","label":"Runtimes for Java Technology"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Java SDK","Platform":[{"code":"","label":""}],"Version":"","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}},{"Product":{"code":"SS7K4U","label":"WebSphere Application Server for z\/OS"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":" ","Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"6.1;6.0","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21251464