Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to time out a non-responding method call. 1

Status
Not open for further replies.

mixer

Programmer
Jan 11, 2000
14
0
0
US
I have a class that makes a call to an AS/400 op system routine. Usually that routine will issue a return code indicating success or failure, but sometimes it hangs and returns nothing. My process is left waiting forever for the return code it will never get. So, I need some method to time out my call to this proc. The following is a psuedo-code example of the process.

class lookUp extends Thread{
public void run(){
boolean p = false;
String[] a = new String{someData elements...

for(int 1 = 0; i< a.length; i++){
p = new AS400Call(a); // how to time this out
// after a minute or so?
if (p) { do success processing }
else { do failure processing }
yield();
// apparently never getting to the yield if no
// response from AS400Call()and other threads
// suffer.

}
}
}

Any ideas would be appreciated.


 
not sure how exactly to implement it, but what about starting a seperate thread with the timer class have the threat wait x number of seconds, when the time hits the amount of time, see where the process is at and kill it if nothing is happening. Assuming that to get data from the AS400 machine it takes relatively no time and you're moving huge amounts of data. Have your thread look at the for loop counter, wait 60 or whatever amount of seconds or minutes, and when the time expires see what the value is at. if the value has changed, reset the timer and the known index to the current one. If the counter hasn't moved or increased in size kill the process. When your for loop exits, kill the timing thread. Again, not sure how to do it, but you may get some ideas from
Good luck, hope this helped even in the slightest way.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top