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
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
Does your thread use ALL of the processor time?
ASKER
I am not sure. What should i do in the thread.
Thanx
Thanx
ASKER
Looks like it. cpu usage is 100%. I dont have that
thread only 6%. How can solve this problem ?
Thanx
thread only 6%. How can solve this problem ?
Thanx
Hmmm....can you post your servlet and thread code?
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("Premad eENCs" + e.getMessage());
}
String dbDriver="sun.jdbc.odbc.Jd bcOdbcDriv er";
String xmlFile = chartServerHome + "\\Support\\Servlet\\ENCZi ppingArgs. 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(th is.xmlFile );
argumentSets.createFromXML ();
argumentSetsList = argumentSets.getArgumentSe ts();
db = new DbBean();
db.setDbDriver(this.dbDriv er);
for (int idx=0; idx <= 4; idx++) {
cZipping zipping = new cZipping(db);
cArgumentSet argumentSet = new cArgumentSet();
argumentSet = (cArgumentSet)argumentSets List.get(i dx);
zipping.makeConnection(arg umentSet);
zipping.setEncRoot();
zipping.mainProcess(argume ntSet);
zipping.closeConnection();
} // for
}
}
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(
InputStream is1 = p1.getInputStream();
BufferedReader br1 = new BufferedReader (new InputStreamReader(is1));
chartServerHome = br1.readLine();
br1.close();
is1.close();
}
catch (IOException e) {
System.out.println("Premad
}
String dbDriver="sun.jdbc.odbc.Jd
String xmlFile = chartServerHome + "\\Support\\Servlet\\ENCZi
long DELAY = 7200000L; // 60*60*1000*2 every 2 hours 10000L;
cMakePremadeENCs runner = new cMakePremadeENCs(dbDriver,
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(th
argumentSets.createFromXML
argumentSetsList = argumentSets.getArgumentSe
db = new DbBean();
db.setDbDriver(this.dbDriv
for (int idx=0; idx <= 4; idx++) {
cZipping zipping = new cZipping(db);
cArgumentSet argumentSet = new cArgumentSet();
argumentSet = (cArgumentSet)argumentSets
zipping.makeConnection(arg
zipping.setEncRoot();
zipping.mainProcess(argume
zipping.closeConnection();
} // for
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it *might* help....
And it will show if it is running :-)
And it will show if it is running :-)
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.
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
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
ASKER
Thanx alot again Time.
Have a nice day.
Have a nice day.
:-)