server response late and redirecting to user defined page

Hi Can any body tell how to know server response time if perticular time reached it should redirect to userdefined page saying that server is busy pls try after some timehere i am using iplanet web server and ias application server
[259 byte] By [audippaa] at [2007-11-27 9:04:40]
# 1
Are you talking about when the server is actually busy and can not handle all of the requests or are you talking about you are processing the request in a Servlet or JSP and you want to send a message if the processing exceeds a certian length of time?
tolmanka at 2007-7-12 21:38:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
yes exactly sirhow can we handle thisThanks in advance
adipanaidu@gmail.coma at 2007-7-12 21:38:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
how it possible in both scenarios SirThanks in advance
adipanaidu@gmail.coma at 2007-7-12 21:38:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

There is not much you can do if the server is too busy to handle your request. You may be able to configure the server to return a custom page.

In the case of a long running process you can do something the following

package com.test;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class ServletTimeTest extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) {

try {

//Create object to get results of sub-thread

ServletTimeTestResults resultObject = new ServletTimeTestResults();

//Create sub-thread

Thread servletTimeTestThread =

new Thread(

new ServletTimeTestThread(

resultObject, Thread.currentThread()));

//start sub-thread

servletTimeTestThread.start();

//Wait ten seconds for sub-thread to finish processing

try {

Thread.sleep(10000);

} catch (InterruptedException ie) {

//sub-thread has finished in less than 10 seconds

System.out.println("Servlet sleep interrupted");

}

//set the flag to make sure sub-thread stops processing

resultObject.setStopProcessing(true);

//check if sub-thread completed processing sucessfully

if (resultObject.isProcessingComplete()) {

//if sub-thread did finish processing then return results from

//resultObject here.

System.out.println("Processing completed");

} else {

//if sub-thread did not finish processing then redirect to

//error page here.

System.out.println("Processing IS NOT completed");

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

package com.test;

/**

* sub-processing thread.

*

* @author Tolmke

*

*/

public class ServletTimeTestThread implements Runnable {

//Object to facilitate inter-thread communication

ServletTimeTestResults resultObject;

//Callback handle to servlet thread

Thread mainThread;

public ServletTimeTestThread(

ServletTimeTestResults resultObject,

Thread mainThread) {

this.resultObject = resultObject;

this.mainThread = mainThread;

}

public void run() {

boolean wait = true;

int count = 0;

//main processing thread. Need to periodically check resultObject.isStopProcessing()

//to determine if main thread wants to terninate sub-processing

while ((wait) && (this.resultObject.isStopProcessing() == false)) {

try {

Thread.sleep(1000);

System.out.println("In proecessing thread...................");

//count can be set to values greater or less than 10 seconds to test

//various scenarios

if (count++ > 3) {

wait = false;

}

} catch (InterruptedException ie) {

ie.printStackTrace();

}

}//End while

//If servlet thread did not set falg indicating timed out then set

//processing successfully completed lag.

if (this.resultObject.isStopProcessing() == false) {

this.resultObject.setProcessingComplete(true);

}

//if servlet thread has not timed out then interrupt the

//the thread from th esleep state.

this.mainThread.interrupt();

}//End run method

}//End class ServletTimeTestThread

package com.test;

/**

* Object to facilitate communication between main servlet thread

* and a processing sub-thread.

*

* @author Tolmke

*

*/

public class ServletTimeTestResults {

//Flag indicating sucessful completion of processing

private boolean processingComplete;

//Flag indicating that sub-process should stop processing

private boolean stopProcessing;

public boolean isProcessingComplete() {

return processingComplete;

}

public void setProcessingComplete(boolean processingComplete) {

this.processingComplete = processingComplete;

}

public boolean isStopProcessing() {

return stopProcessing;

}

public void setStopProcessing(boolean stopProcessing) {

this.stopProcessing = stopProcessing;

}

}

tolmanka at 2007-7-12 21:38:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
I will implement this in my codingThank you very much sir
adipanaidu@gmail.coma at 2007-7-12 21:38:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...