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.
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 ?
Joined: Jan 19, 2011
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.