Wednesday, October 12, 2005

Tomcat lost connection with MySQL server

While working on a project with Tomcat server and MySQL database, I got an exception saying something like "Lost connection to MySQL server".
This problem I faced every morning at the start of a day.
i.e. If I use my application before leaving for a day and if server was left RUNNING, on the next morning when I try to use application again, above exception was thrown.

Problem here was, MySQL's variable "interactive_timeout".
Definition of "interactive_timeout" from MySQL manual is as follows -
"The number of seconds the server waits for activity on an interactive connection before closing it."
This variable's default value is 28800 i.e. 8 hrs.
So when I kept my server running all the night, no interaction was there on connection and server was closing the connection.
This connection was tried to be used by my application and hence above exception was thrown.

Some of the solutions to this problem are
1. If you are using connection pooling, keep the connection interactive so that it is never idle for ${interactive_timeout} seconds
2. Change the value of variable on MySQL server as per your requirement (This solution, I think, is not the best solution)
3. Before firing any query to server, check whether connection is active or not

Drop a comment to let me know whether this helped you in solving the problem.

Thanks.

Tuesday, October 04, 2005

Tomcat /servlet problem

After coding and deploying my first servlet application on Tomcat 5.0, I entered following URL in browser to test the servlet.

http://machineName:portNumber/webapplication/servlet/servletName

This did not work and I got "HTTP 404" error.
I tried to run same servlet application on Resin and it worked.

After googling a little, I came to know that the file
"installationDirectory"\Apache Software Foundation\Tomcat 5.0\conf\web.xml
is responsible for the mapping "/servlet/servletName" to our servlet.

In newer Tomcat versions, this mapping is disabled for some reason I don’t know.

To enable this /servlet/* mapping, you have to uncomment two things:
- servlet "invoker" in <servlet> and
- servlet mapping for /servlet/* which is mapped to "invoker" servlet in <servlet-mapping>

After uncommenting these two things, restart the server and things should go fine.

Do let me know if this doesn’t work.

If anybody have any idea about why /servlet/* mapping is disabled in Tomcat's latest versions, drop me your comment.

Introduction

Hi,
If you are here to read something philosophical, some of my past experiences, some views of mine on world issues, good English then this blog is not for you.

I am a software engineer and I am creating this for my fellow mates.

In our everyday life, we face lot of problems while coding, configuring servers, logging data.. etc. Here I will share all the problems I faced, while working, along with its solution.
I am in no way responsible if anything goes wrong in your system while you are trying any of the solutions written here.

You can refer this only as a guideline to your problem and solutions, stated here, may differ with version of your APIs or platform you are working on.
I will try my best to put all the version details in my blog while stating problems and while giving solutions to them.

Thanks.