Link to home
Start Free TrialLog in
Avatar of b3cf
b3cf

asked on

Cannot access jsp page when servlet is running

Hi

 I have a servlet that is started automatically when Tomcat starts.

This servlet starts a class (in the init method) that extends the Thread
class. There i have a method that does zipping of some files.
After that it goes to sleep for some time and continues the same
process. This works fine but when i try to connect to the main jsp page
it says "unable to find localohost:8080".

Does someone know why ?

Thanx alot
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Does your thread use ALL of the processor time?
Avatar of b3cf
b3cf

ASKER

I am not sure. What should i do in the thread.

Thanx
Avatar of b3cf

ASKER

Looks like it. cpu usage is 100%. I dont have that
thread only 6%. How can solve this problem ?

Thanx
Hmmm....can you post your servlet and thread code?
Avatar of b3cf

ASKER

I just put yield() in the thread code. Now the cpu
usage is 1%. But still cannot access the jsp page.  


Servlet
-------

public class PremadeENCs extends HttpServlet {

   public void init (ServletConfig config) throws ServletException {

          String chartServerHome = "";
          super.init(config);

          try {
               Process p1 = Runtime.getRuntime().exec("cmd.exe /c echo %CHART_HOME%");
               InputStream is1 = p1.getInputStream();
               BufferedReader br1 = new BufferedReader (new InputStreamReader(is1));
               chartServerHome = br1.readLine();
               br1.close();
               is1.close();
          }
          catch (IOException e) {
                 System.out.println("PremadeENCs" + e.getMessage());
          }

          String     dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
          String     xmlFile = chartServerHome + "\\Support\\Servlet\\ENCZippingArgs.xml";
          long       DELAY = 7200000L; // 60*60*1000*2 every 2 hours 10000L;

          cMakePremadeENCs runner = new cMakePremadeENCs(dbDriver, xmlFile, DELAY);
          runner.run();

   }
}

Thread class
------------

import java.util.*;

public class cMakePremadeENCs extends Thread {

   private String dbDriver;
   private String xmlFile;
   private long DELAY;

   public cMakePremadeENCs(String dbDriver, String xmlFile, long DELAY) {
          super();
          this.dbDriver = dbDriver;
          this.xmlFile = xmlFile;
          this.DELAY = DELAY;
   }

   public void run() {
          while(true) {
               try {
                   doProcess();
                   sleep(this.DELAY);
                   yield();
               }
               catch (InterruptedException ex) {
                      ex.printStackTrace();  // shouldn't happen
               }
          } // while
   }

   public void doProcess() {

          ArrayList  argumentSetsList;
          DbBean db;

          cArgumentSets argumentSets = new cArgumentSets();
          argumentSets.setXMLFile(this.xmlFile);
          argumentSets.createFromXML();

          argumentSetsList = argumentSets.getArgumentSets();

          db = new DbBean();
          db.setDbDriver(this.dbDriver);

          for (int idx=0; idx <= 4; idx++) {
               cZipping zipping = new cZipping(db);
               cArgumentSet argumentSet = new cArgumentSet();
               argumentSet = (cArgumentSet)argumentSetsList.get(idx);
               zipping.makeConnection(argumentSet);
               zipping.setEncRoot();
               zipping.mainProcess(argumentSet);
               zipping.closeConnection();
          } // for

   }
}
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it *might* help....

And it will show if it is running :-)
Avatar of b3cf

ASKER

Thanx alot Tim. It works fine.

But why ?

I set the  priority to 1. (lowest ?)
 runner.setPriority(1);

But when the thread is running i cannot run some things.
Any idea ?

Thanx alot. Appreciate alot your help.
Not 100% sure why my one works, and yours doesn't...

I know that you should only extend Thread if you want to alter it's behaviour from the default -- but that's more of an Object Oriented design pattern than a hard and fast rule...

Maybe Tomcat was getting locked at the end of the init() method, as it was waiting for the Thread to end...

------------

> I set the  priority to 1. (lowest ?)
> runner.setPriority(1);

I can never remember which is min...

So I always use:

runner.setPriority( Thread.MIN_PRIORITY ) ;

If stuff still doesn't really work when it is running, I guess it is the fault of the DBBean or cZipping classes being too processor hungry :-(

Maybe the odd Thread.yield() in their most busy sections would ease the pain a little?

Glad I could help :-)

Even if I couldn't really explain ;-)

Tim
Avatar of b3cf

ASKER

Thanx alot again Time.
Have a nice day.