Saturday 16 February 2019

java.sql.SQLRecoverableException: Closed Connection

We are getting below exception “java.sql.SQLRecoverableException: Closed Connection” error on JBoss instance.

Error log:
 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/WebApp].[WebApp]] (http--
Servlet.service() for servlet WebApp threw exception: java.sql.SQLRecoverableException: Closed Connection
at oracle.jdbc.driver.PhysicalConnection.commit( [ojdbc6.jar:]
at oracle.jdbc.driver.PhysicalConnection.commit( [ojdbc6.jar:]
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.jdbcCommit(
at org.jboss.jca.adapters.jdbc.WrappedConnection.commit(
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit( [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit( [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit( [spring-orm-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at [spring-tx-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at [spring-tx-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning( [spring-tx-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction( [spring-tx-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke( [spring-tx-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( [spring-aop-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept( [spring-aop-3.2.5.RELEASE.jar:3.2.5.RELEASE]

What is java.sql.SQLRecoverableException: Closed Connection?

Above exception is due to one of these reasons this may due to the lower version of Oracle [ojdbc6.jar], network issue, firewall timeout configuration or database timeout.
The timeout should properly check or configured in JBoss, the value must be greater than 0 but less than timeout has been used in a database, network firewall, etc.

But as per my case, Oracle [ojdbc6.jar] is lower version as per database server required.

How to check ODJBC.jar version using the command line?

Command:   java  -jar  ojdbc6.jar  -version

Solution: We should use the same Oracle database JDBC driver version as per the database version.

Thanks :-)

Thursday 14 February 2019

java.lang.VirtualMachineError: out of space in CodeCache for adapters

Code Cache issue:

We are getting below exception “java.lang.VirtualMachineError: out of space in CodeCache” error on JBoss instance

Error log:
 11:19:08,460 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/WebApplication].[default]] (ajp-/ Servlet.service() for servlet default threw exception: java.lang.VirtualMachineError: out of space in CodeCache for adapters
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.6.0_35]
at java.lang.Class.privateGetDeclaredConstructors( [rt.jar:1.6.0_35]
at java.lang.Class.getDeclaredConstructors( [rt.jar:1.6.0_35]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors( [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]
at [spring-beans.jar:3.1.1.RELEASE]

What is CodeCache ??
The Java Virtual Machine (JVM) generates native (compiled) code and stores it in a memory area called the codecache. The code cache is where jar definitions are stored.
The default maximum size of the CodeCache on most of the platforms is 48M. If any application needs to compile a large number of methods resulting in a huge amount of compiled code then this CodeCache may become full. 
You can set the code cache size by setting the property -XX:ReservedCodeCacheSize and monitor it by tools like JConsole. When the code cache becomes full, the Java VM flushes and sweeps it. In Java 7 and higher, code cache flushing is enabled by default.

Codecache Size Options:-

160K (varies)
Initial code cache size (in bytes)
Reserved code cache size (in bytes) - maximum code cache size
Code cache expansion size (in bytes)

Steps to check CodeCache Size in JBOSS:

Step 1: Locate to $JBOSS_Home/bin

Step 2: Command to connect JBoss instance :

            Command jboss-cli.bat -c --controller=localhost:9999

Step 3: Command to check CodeCache size in JVM.

            Command:    /core-service=platform-mbean/type=memory-pool/name=Code_Cache/:read-resource(recursive=true,proxies=true,include-runtime=true,include-defaults=true)

Step 4: Output as follows:

    "outcome" => "success",
    "result" => {
        "name" => "Code_Cache",
        "type" => "NON_HEAP",
        "valid" => true,
        "memory-manager-names" => ["CodeCacheManager"],
        "usage-threshold-supported" => true,
        "collection-usage-threshold-supported" => false,
        "usage-threshold" => 0L,
        "collection-usage-threshold" => undefined,
        "usage" => {
            "init" => 2555904L,
            "used" => 99788096L,
            "committed" => 100663296L,
            "max" => 100663296L
        "peak-usage" => {
            "init" => 2555904L,
            "used" => 99797824L,
            "committed" => 100663296L,
            "max" => 100663296L
        "usage-threshold-exceeded" => true,
        "usage-threshold-count" => 0L,
        "collection-usage-threshold-exceeded" => undefined,
        "collection-usage-threshold-count" => undefined,
        "collection-usage" => undefined

Step 5: Increase a CodeCache size by “-XX:ReservedCodeCacheSize=128M” in  JBOSS JVM  argument.

Reference URL :


Tuesday 12 February 2019

Apache Rewrite Rules

  • Apache provides a REWRITE RULE function to redirect the requests from one URL/Page to another URL/Page.
  • To use this functionality we have to enable the mod_rewrite module in apache web server.
  • mod_rewrite provides a flexible and powerful way to manipulate URLs using an unlimited number of rules. 
  • mod_rewrite operates on the full URL path, including the path-info section. A rewrite rule can be invoked in httpd.conf or in .htaccess file.

Enable module:
  • LoadModule rewrite_module modules/

NOTE: We should not always use .htaccess file for large number of rewrite rule redirection, since which may leads to the slowness of Apache server.

#####Forward/Rewrite , main domain towards application context.

RewriteEngine on
RewriteRule   ^/$     /CONTEXT/ [R]

RewriteRule Basics
A RewriteRule consists of three arguments separated by spaces. The arguments are
  • Pattern: which incoming URLs should be affected by the rule;
  • Substitution: where should the matching requests be sent;
  • [flags]: options affecting the rewritten request.

The Substitution can itself be one of three things:

A full filesystem path to a resource
  • RewriteRule "^/games"  "/usr/local/games/web"

This maps a request to an arbitrary location on your filesystem, much like the Alias directive.

A web-path to a resource
  • RewriteRule "^/foo$"  "/bar"

If DocumentRoot is set to /usr/local/apache2/htdocs, then this directive would map requests for to the path /usr/local/apache2/htdocs/bar.

An absolute URL

  • RewriteRule "^/product/view$"  "" [R]

Rewrite Conditions

For example, to send all requests from a particular IP range to a different server, you could use:

RewriteCond  "%{REMOTE_ADDR}"  "^10\.2\."
RewriteRule  "(.*)"


Redirect All Website Pages

# Redirect all pages from # to
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$$1 [R=301,L]

Meta Refreshes:

This method uses a special Meta tag in the HTML source to control the redirect. In the early days of the Internet, this was the main method of generating redirects.
The meta refresh should appear within the head section of the HTML source.

An example is:

<meta http-equiv="Refresh" content="0; url=" />

The number (0 in this example) refers the the number of seconds to wait before performing the redirect. A zero second delay results in an instant redirect and is the equivalent of doing a 301 permanent redirect.

Reference link:

Redirect rule for old page to new page:

RewriteEngine On
Redirect permanent   /page1.html
Redirect permanent   /folder/page2.html

Reference link:

 Redirect a portion of your site to HTTPS, you might do the following:

    Redirect "/admin/" ""

Redirect all requests from the www to the non-www version of the domain, or vice-versa:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$ "$1" [R=301,L]

Reference link:

PHP Redirects :
If you want to do a PHP 301 permanent redirect, you just need to add the redirect code, ie:


Reference link:

Rewriting from Old to New (external):
We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view:

RewriteEngine  on
RewriteRule    "^/foo\.html$"  "bar.html"  [R]

Reference link:

Redirect all pages from Http to Https:

<VirtualHost *:80>

  Redirect "/" ""


RewriteEngine On
RewriteRule ^/$  https://%{HTTP_HOST}/ [R,L]
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,L]

RewriteEngine On
RewriteCond %{HTTPS}  !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L

Redirect all pages from Https to Http:

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{SERVER_PORT} ^443$ [OR]
        RewriteCond %{HTTPS} =on
        RewriteCond %{HTTP_HOST} !^$
        RewriteRule ^/(.*) http://%{HTTP_HOST}/$1 [L,R]

Redirect a URL to

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$
RewriteRule (.*)$1 [R=301,L]

Redirect request from url to

<VirtualHost _default_:443>
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$1 [L,R]

Alias & AliasMatch  Directive:

The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot.

Alias "/image" "/ftp/pub/image"
Alias "/icons/" "/usr/local/apache/icons/"

Note that if you include a trailing / on the URL-path then the server will require a trailing / in order to expand the alias

A request for would cause the server to return the file /ftp/pub/image/foo.gif.

Reference link:

mod_rewrite offers detailed logging of its actions at the trace1 to trace8 log levels.

LogLevel alert rewrite:trace3

To check the logs :
tail -f error_log|fgrep '[rewrite:'

Redirect Detective is a free redirect checker

Reference links:

Thanks :-)