?
Solved

JBuilder: Tomcat needs to be restarted every day

Posted on 2005-05-10
20
Medium Priority
?
362 Views
Last Modified: 2013-11-24
Hello experts, I'm using JBuilder Enterprise 11
and have some existing code.
The code on the server side needs the Tomcat "jakarta-tomcat-5.5.9".
For the testing environment the Tomcat is started
  using its delivered "bat" procedures ["shutdown.bat" and] "startup.bat".
The problem is now that the Tomcat needs to be restarted every day.
Is there a way to get rid of this?

       Any help is appreciated.  
 
             HStrix  
 
0
Comment
Question by:HStrix
  • 11
  • 5
  • 4
20 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13975260
Why does it need to be restarted exactly?

You can run it as a service if that will help you.
0
 
LVL 92

Expert Comment

by:objects
ID: 13975262
0
 

Author Comment

by:HStrix
ID: 13975352
I'm running the Tomcat not as service
because I want to write some messages using System.out.println("any info"); as protocol info.
These messages appear in the console window.

Trying to access the server environment I got the message
---
java.sql.SQLException: Connection.close() has already been called. Invalid operation in this state.
---
The other messages are already gone so I don't can write them here.
I need to wait till next day.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 92

Expert Comment

by:objects
ID: 13975366
Why aren't you writing them to the logs?
tomcat may actually log stdout as well anyway, check the logs directory

That error looks to be caused byy attempting to close a db connection that is already closed.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13977828
> The problem is now that the Tomcat needs to be restarted every day.
Asking again, why is that the case?
0
 

Author Comment

by:HStrix
ID: 13978958
I'll check again next morning the messages.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13979019
Does it crash every day?
0
 

Author Comment

by:HStrix
ID: 13979326
Till now we needed to restart Tomcat every day.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13979953
>> Till now we needed to restart Tomcat every day.
Ok, that is strange as there should not be such need unless your webapp is getting into a bad state (memory leak, dead/live lock or any other problem).
0
 

Author Comment

by:HStrix
ID: 13984083
Accessing the environment this morning I got the following messages:
---
SELECT myfields from mytable  order by myid
java.sql.SQLException: Communication link failure: java.io.EOFException, underlying cause: null

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1394)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1538)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
        at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1224)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2248)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2196)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:1163)
   ... other messages related to the application and apache (catalina)
** END NESTED EXCEPTION **
...
java.sql.SQLException: Connection.close() has already been called. Invalid operation in this state.
---
After restarting the Tomcat everything is running as expected
and this remains so for the entire day.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13985314
How do you get the jdbc connection?
Do you use Tomcat datasource or are you using the DriverManager.getConnection directly. (I think it is the latter).
You can't use a jdbc connection once you closed it. You need to create a new one instead.
Don't keep long reference to the DB connection and create a new one onced one was closed.
Consider using Tomcat DS as it pools your connections. see: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
0
 

Author Comment

by:HStrix
ID: 13986250
I copied
  mysql-connector-java-3.0.16-ga-bin.jar
to tomcat directory only:
  *\jakarta-tomcat-5.5.9\common\lib

The connection is established using
---
   public void odbcConnect()throws Exception
   {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String temp="jdbc:odbc:"+this._database;
         this._conn = DriverManager.getConnection(temp);
         if(this._conn!=null)
           {
             this._stmt = _conn.createStatement();
             System.out.println("connected.");
           }
         else System.out.println("No connection");
         this._connectError=false;
   }
---
0
 
LVL 92

Expert Comment

by:objects
ID: 13991116
That code does not use your mysql driver, do you get a db connection elsewhere in your code
Can you post the rest of the stack trace
0
 

Author Comment

by:HStrix
ID: 13993590
That is the stack trace from this morning after 1st access:
---
java.sql.SQLException: Communication link failure: java.io.EOFException, underlying cause: null

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1394)
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1538)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
        at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1224)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2248)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2196)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:1163)
          at mydb.RunSql.runSelect(RunSql.java:198)
          at mybean.getData(mybean.java:939)
          at myAdmin.getData(myAdmin.java:334)
          at MyServlet.doPost(MyServlet.java:243)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419)
        at org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:169)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)


** END NESTED EXCEPTION **
---

The Tomcat is running in a console window; the OS is Win2003; Apache's version is 2.0.54.
I'm unsure, but perhaps a timeout has occured?
But where can I find such an information?
0
 

Author Comment

by:HStrix
ID: 13993907
I checked mysql and it is working without any problems.
0
 
LVL 15

Accepted Solution

by:
aozarov earned 2000 total points
ID: 13996728
Add to your jdbc url "autoReconnect=true"
e.g.
jdbc:mysql://db-host:3306/DBName?autoReconnect=true
This is a mySQL driver specific feature.
In general (without such a feature) don't expect to create a jdbc connection once and expect it to live forever as there can be many elements that can timeout such connection (the DB, the driver, proxy/firewall, ..).
If the above feature doesn't work for you for some reason then you can apply standards technique like:
1. Test your connection using a simple query before using it (applying queries) and if it’s broken to create a new connection.
2. Create short lived connection (e.g. for every group of queries you create/close a new connection).
The two options above can be done for you if you were using some sort of connection pool such as the one I suggested http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
0
 

Author Comment

by:HStrix
ID: 14016471
Thanks aozarov,
I'll inform you after testing it.

For completeness: the connection to mysql is established using
---
        public static myapplet.database.RunSql runsql=null;
---
        ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
        // is now=>  MYSQLdatabaseName=jdbc:mysql://localhost:3306/mydb?autoReconnect=true
        String mysqldatabase = rb.getString("MYSQLdatabaseName");
        System.out.println("MYSQLdatabaseName jdbc-mysql:"+mysqldatabase);       // <= added
        runsql = new myapplet.database.RunSql(mysqldatabase);
        this._connect = true;
---
0
 

Author Comment

by:HStrix
ID: 14024614
This morning I could check the status of the Tomcat processing.
I needed to notice that introducing the autoReconnect doesn't change anything.
The Tomcat protocol shows exactly the same stack trace as I commented before.
0
 

Author Comment

by:HStrix
ID: 14025018
As an action I introduced several protocol actions in the code
    using System.println...
I hope that will give me more information about the reason.
0
 

Author Comment

by:HStrix
ID: 14043078
In made further checkings,
and the result is:
  The "java.sql.SQLException: Communication link failure: java.io.EOFException, underlying cause: null" occurs
   as I described it before,
   but it is possible to continue working without re-starting the Tomcat.
   So I dont't know the real cause of the problem,
   but it can be skipped/ignored and working can be continued.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month4 days, 19 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question