Archive

Posts Tagged ‘tomcat’

What is default Connector in Tomcat 8

May 23rd, 2016 No comments

What is the default connector option in Tomcat 8 if you do not define explicitly ?

Given this configuration in server.xml

<Connector port="8080" protocol="HTTP/1.1" enableLookups="false" compression="on"

maxThreads="200" acceptCount="100" maxKeepAliveRequests="1" URIEncoding="UTF-8" />

what do you think will be default connector ?

Answer :  NIO(Non blocking connector)

This is the screen shot from Jconsole

default-protocol-tomcat8

From Tomcat documentation

Sets the protocol to handle incoming traffic. The default value is HTTP/1.1 which uses an auto-switching mechanism to
select either a non blocking Java NIO based connector or an APR/native based connector.
If thePATH (Windows) or LD_LIBRARY_PATH (on most unix systems) environment variables contain the Tomcat native library,
the APR/native connector will be used. If the native library cannot be found, the non blocking Java based connector will be used.
Note that the APR/native connector has different settings for HTTPS than the Java connectors.

So even though you have not explicitly defined a connector, tomcat 7, tomcat 8 and above will be using NIO Connector

Now I change the server.xml connector to


<Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol"
 maxThreads="5000" SSLEnabled="false" scheme="https" secure="true"
 socket.appReadBufSize="1024"
 socket.appWriteBufSize="1024"
 clientAuth="false" sslProtocol="TLS"
 enableLookups="false" />

tomcat-connector-protocol

The data is available through JConsole

Categories: Programming / tutorials Tags:

Cross Domain scripting settings on Tomcat

February 23rd, 2011 3 comments

In last post we had explained how to configure Apache to allow cross domain scripting. details can be found here

Cross domain Scripting problem with XmlHttp

If you do not plan to use Apache and for some reasons using tomcat or any other similar web container which supports filter, here is a ready made solution, Cors Filter

This gives you a servlet filter which is compatible with any Java Servlet 2.5+ web container.

Installation is very simple. Add the jar to your libraries

In you web.xml

add this line

<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

And you are all set

Configuring Tomcat with Apache

February 2nd, 2011 4 comments

In this post we will describe how to set up Apache web server with Tomcat.

We have used  Tomcat 6.0.29 and Apache 2.2.17 but the settings describe here will work for Tomcat 7 as well.

1. We will need to install mod_jk on apache

Mod_jk can be downloaded  from this location

http://www.fightrice.com/mirrors/apache//tomcat/tomcat-connectors/jk/binaries/win32/

2. Copy mod_jk-1.2.30-httpd-2.2.3.so to <Install Location>\Apache Software Foundation\Apache2.2\modules

3. Create a workers.properties in conf folder of apache

A sample workers.properties

workers.tomcat_home=/usr/local/jakarta-tomcat-4.1.18

# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/lib/java2

# You should configure your environment slash… ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/

# The workers that your plugins should create and work with
#
worker.list=worker1

#—— DEFAULT ajp13 WORKER DEFINITION ——————————
#———————————————————————
# Defining a worker named ajp13 and of type ajp13
# Note that the name and the type do not have to match.
#
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13

#—— CLASSPATH DEFINITION —————————————–
#———————————————————————
# Additional class path components.
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar

# The JVM that we are about to use
#
# Unix – Sun VM or blackdown
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)i386$(ps)classic$(ps)libjvm.so

# Setting the place for the stdout and stderr of tomcat
#
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

4. Use Tomcat auto configure.

To be added at the end of your httpd.conf

Include $TOMCAT_HOME/conf/jk/mod_jk.conf-auto

5. Re start tomcat and re start Apche.

You will find two folders auto and jk created under TOMCAT_HOME/conf.

http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html

You will also find this value inserted in conf.xml

<Listener className=”org.apache.jk.config.ApacheConfig” modJk=”<Your apache directory>/Apache2.2/modules/mod_jk-1.2.30-httpd-2.2.3.so” />

Common Issues: Read more…

Setting up tomcat for remote debugging

December 28th, 2010 No comments

In windows environment , open up your startup.bat and add to file somewhere in beginning

rem set remote debugger
set JPDA_ADDRESS=8001
set JPDA_TRANSPORT=dt_socket
echo Remote debugging started

Add this to end of your startup.sh file

call “%EXECUTABLE%” jpda start %CMD_LINE_ARGS%

Make sure you comment out

call “%EXECUTABLE%” start %CMD_LINE_ARGS%

When you are connecting with eclipse, set your debug port at 8001

Now when you start your server , you would see the message Remote debugging started


Categories: Programming / tutorials Tags:

Creating a data source for tomcat

November 22nd, 2010 1 comment

To create a datasource in tomcat , add this in your conf/context.xml

<Resource name=”jdbc/TestDB” auth=”Container” type=”javax.sql.DataSource”
maxActive=”100″ maxIdle=”30″ maxWait=”10000″
username=”javauser” password=”mypassword” driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost:3306/javatest”/>
And if you are using Spring applicationContext.xml file, add this to applicationCOntext.xml file

<jee:jndi-lookup id=”dataSource” jndi-name=“jdbc/TestDB” />

Categories: Programming / tutorials Tags: ,

Troubleshooting application performance with VisualVM

November 11th, 2010 1 comment

Those of you who have not heard about VisualVm , we had talked about it in earlier post Performance tuning your java and J2ee applications.
This is one of the best free tools for monitoring the performance of your java/j2ee application. If you try to use VisualVM with myeclipse, you will have to upgrade from basic license of $30 ! But if you follow the rest of the post , I will explain how to do it for free.

Not many people have worked with it but it sure gives you a deeper insight of your application and helps in locating the problematic areas. The motivation for us was to identify the out of memory exceptions were facing in our application and pinpoint the cause.

In this post we will talk about Visual VM, setting it up with your eclipse and how to monitor your application. We will set up a web application and run visualVM to monitor the application

1. What is Visual VM

Java Management Extensions (JMX) had been part of java since JDK 5.0. JMX enables you to get all the information from the JVM.  VisualVM is a visual tool that integrates some of the commandline JDK tools and gives you powerful profiling capabilities.  VisualVM uses JMX and gives you detailed info about JVM memory, CPU usage, Garbage Collection . It can also profile your objects for CPU and memory usage suggested for local JVM’s only.

More about VisualVM

2.  Installing Visual VM

Visual VM comes bundled with your JDK install ,(post JDK 1.6 update 7). Alternatively you can go to https://visualvm.dev.java.net/download.html and download the file.

Once installed , go to <installed directory>/bin and click visualvm.exe.

It will fire up the visualVM for you. Read more…

How to enable verbose garbage collection in tomcat ?

October 7th, 2010 No comments

If you had been working with Tomcat in production performance or out of memory issues, take a look at our recnet posts on How to increase heap size on tomcat and Increasing permgen on your tomcat server.

Now comes another important part. How do you know your tomcat is loading / unloading classes as you have been thinking . How is GC happening and is it causing the bottleneck ?

Well simple answer is enable the verbose GC settings on tomcat.

How do you do that ?

On Windows :

set JAVA_OPTS=-XX:+PrintGCDetails -XX:-HeapDumpOnOutOfMemoryError -verbose:gc

On Linux :

You can add on catalina.sh .You may also want to check the file under $TOMCAT_HOME/bin/setenv.sh/.bat.

Add the above line in this file.

Categories: Programming / tutorials Tags: ,

Increasing Permgen size in your Server

October 5th, 2010 No comments

In our previous posts , we had talked about Increasing the Heap size of your server

Here will talk about the Permgen space , how it is different from heap size and why just increasing the heap size will not help you in getting rid of this error  Java.lang.OutOfMemoryError: PermGen space

The permanent generation should not be ignored, because you need enough memory allocated to it to hold all classes in all of your applications including the JSP’s. So if you have an application which uses a good number of third party libraries , has lot of files , you will definitely need a lot of Permgen space. If you are running two applications on the same server , definitely allocate some good chunk of memory to your Perm gen.

How to increase PermGen ?

When you add this line in your catalina.bat or catalina.sh

set JAVA_OPTS=-Xms128m -Xmx192m

It only increase heap size. This is how it would look like (assuming your default PermGen is 64MB)

Increasing PermGen on tomcat

PermGen does not change

To increase PermGen , it would be

set JAVA_OPTS=-Xms128m -Xmx192m -XX:MaxPermSize=256m

See how the size of PermGen has increased.

Perm Gen increased

Perm Gen increased

This was done on Tomcat 6.0.14