• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time out inside a servlet

 
Frank Hamilton
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to implement a time out system inside a doget servlet method. This method try to connect with a nfs server, if It not respond in 5 second then i need to redirect a error.jsp page.
Can somebody tell my what is the best way to do this work.
Thank so much.
 
Jatin Dhingra
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I guess, you would be using while(true) loop to get connected to the server. Make a variable that holds system time when servlet was instantiated( out of while loop) and make other variable that notes system time each time while loop is executed ( it will be inside while loop). Then inside while loop, check condition that if difference between two "time variables" is more than 5 seconds execute a break statement.

does that sound helpful ?
 
Frank Hamilton
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank so much Jatin,

I think this solution not work for me.
Inside my servlet I use WEBNFS for creating a nfs client and access to a remote directory. I need a time out if the nfs server is down but I think this api don't give me any mechanism for me pourpose. Therefore I think any mechanism, maybe a thread, can help me.
This is my code:


I think your solution not work because the file.exist() method wait for the connexion and the time variable inside the while never increment.

Anybody can help me with this problem?. I think nsf is over tcp protocolo and maybe can use some tcp connector method try to connect with nfs server and if the server is down this method throw a timeout.

 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please initiate/run a TimerTask from your Servlet, for the duration required and try to get a feedback from it. Based on what it returns, you can take the next step.
 
Frank Hamilton
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Madhan, thanks for your replay.

I solved my problem with the information in this post http://www.coderanch.com/t/533484/java/java/NFS-time-out, it's work fine for me. I'll probe TimerTask when I have same time, it's looking good.

Thank.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic