During performance testing execution on my application stack I came across following fault multiple times. My application stack uses Apache Tomcat 7 and JDK 1.7.0_55.
After investigation found that this is a bug in JDK JIT compiler which is fixed in later version started from update 60.
I had to get the release out and could not afford to upgrade the JDK version so used "-XX:-LoopUnswitching" switch to disable the loop unswitching.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00002aaab0363f9e, pid=28321, tid=1102854464
#
# JRE version: 7.0_25-b15
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# J org.apache.http.impl.cookie.BestMatchSpec.formatCookies(Ljava/util/List;)Ljava/util/List;
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid28321.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#
Showing posts with label tomcat. Show all posts
Showing posts with label tomcat. Show all posts
Tuesday, November 29, 2016
Thursday, November 19, 2009
SpringSource Tool Suite
I have started using STS for the past 3-4 months. The tool is powered by the latest Eclipse version Galileo and comes bundled with useful plugins for Spring based development. The tool also comes with the maven plugin bundled in. I always use Maven and Spring for all my Java projects so I am enjoying this tool.
The suite also comes with Apache Tomcat server called TC Server. The server comes with a web application named "Insight". This web application tracks performance of the web applications deployed in this server. The application have a nice UI to drill down the statistics to pin point the code hampering the performance. No doubt the tool is very helpful to debug the code and find the performance bottlenecks. The beauty is no configurations are required at all.
The suite also comes with Apache Tomcat server called TC Server. The server comes with a web application named "Insight". This web application tracks performance of the web applications deployed in this server. The application have a nice UI to drill down the statistics to pin point the code hampering the performance. No doubt the tool is very helpful to debug the code and find the performance bottlenecks. The beauty is no configurations are required at all.
Friday, October 30, 2009
Configure Log4j for a web application on Apache Tomcat
Today I stumbled upon a problem of configuring log4j for a web application on Apache Tomcat. The problem is where to keep the log4j.xml and how initialize the logging system. One way is to keep the log4j.xml anywhere and change the Tomcat startup script to add -Dlog4j.configuration=<log4j.xml file path> but I do not want to depend on a change in Tomcat startup script.
I tried all the possible places but it did not work. I realized unless I define the log4j.configuration system parameter it will not work. I then looked at log4j api and found DOMConfigurator class which initializes the log4j system from log4j.xml.
Here is what I done to keep all configurations inside my application.
Create a listener class as shown below to initialize the log4j using the log4j.xml deployed with your application.
Add these entries to your web.xml. Here we are defining a parameter to configure the log4j.xml file path and registering the above created listener.
<pre>
<context-param>
<param-name>log4jXMLFilePath</param-name>
<param-value>WEB-INF/classes/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>Log4jInitializationListener</listener-class>
</listener>
</pre>
Start the application to confirm log4j is working. I have used the following log4j configuration so here it creates a server.log file.
I tried all the possible places but it did not work. I realized unless I define the log4j.configuration system parameter it will not work. I then looked at log4j api and found DOMConfigurator class which initializes the log4j system from log4j.xml.
Here is what I done to keep all configurations inside my application.
Create a listener class as shown below to initialize the log4j using the log4j.xml deployed with your application.
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
public class Log4jInitializationListener implements ServletContextListener {
public Log4jInitializationListener() {
}
public void contextInitialized(ServletContextEvent servletContextEvent) {
DOMConfigurator.configureAndWatch(servletContextEvent.getServletContext().getInitParameter("log4jXMLFilePath"));
Logger logger = Logger.getLogger(Log4jInitializationListener.class);
logger.debug("Log4j working");
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
Add these entries to your web.xml. Here we are defining a parameter to configure the log4j.xml file path and registering the above created listener.
<pre>
<context-param>
<param-name>log4jXMLFilePath</param-name>
<param-value>WEB-INF/classes/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>Log4jInitializationListener</listener-class>
</listener>
</pre>
Start the application to confirm log4j is working. I have used the following log4j configuration so here it creates a server.log file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="RollingFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="server.log"/>
<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %l - %m%n" />
</layout>
</appender>
<root>
<priority value="debug"/>
<appender-ref ref="RollingFileAppender"/>
</root>
</log4j:configuration>
Monday, May 18, 2009
How to configure a datasource in Apache Tomcat
I have to build a POC (proof of concept) using JDK6, Spring, Hibernate and Apache CXF on Apache Tomcat. I will be using Maven build tool and Nexus repository. My IDE is Eclipse with m2eclipse and spring IDE plugin. In a nutshell we need a webservice application and I have chosen these technologies to develop the solution. I thought it would be a good idea if I blog on how I developed this POC. I will do step-by-step development.
Lets start with "How to configure a datasource in Apache Tomcat".
There is another way of configuring datasource in Tomcat, but I prefer this solution as the configuration resides in the application war file. Simply copy your war file in a tomcat server along with the required jdbc jar and your application is up and running. I wish I can bundle the jdbc jar also in war but unfortunately it doesn't work.
Create a file name "context.xml" (any other name will not work) in META-INF directory of your war file. The content of the context.xml will look like this -
Add this in the web.xml of your war -
The res-ref-name should match the //Resource@name defined in the context.xml
Copy the required jdbc driver jar in $TOMCAT_HOME/lib directory. In this case its mysql-connector-java-5.1.6.jar for mysql database.
Lets start with "How to configure a datasource in Apache Tomcat".
There is another way of configuring datasource in Tomcat, but I prefer this solution as the configuration resides in the application war file. Simply copy your war file in a tomcat server along with the required jdbc jar and your application is up and running. I wish I can bundle the jdbc jar also in war but unfortunately it doesn't work.
Create a file name "context.xml" (any other name will not work) in META-INF directory of your war file. The content of the context.xml will look like this -
<Context path="/travel" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/travel" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="user" password="password" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/travel?autoReconnect=true"/>
</Context>
Add this in the web.xml of your war -
<resource-ref>
<description>Datasource</description>
<res-ref-name>jdbc/travel</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
The res-ref-name should match the //Resource@name defined in the context.xml
Copy the required jdbc driver jar in $TOMCAT_HOME/lib directory. In this case its mysql-connector-java-5.1.6.jar for mysql database.
Subscribe to:
Posts (Atom)