简体   繁体   中英

Delay between request/response

The problem: I have 2 methods:

proccessRequest();
proccessResponse();

if I run them so then I get an error because the request proccessing take too long and the response part gives an error. But if I add Thread.sleep(300); between them, then it run fine.

proccessRequest();
Thread.sleep(300);
proccessResponse();

What would be a good solution for this? Stopping the app with Thread.sleep isnt a good solution. Should I use some kind of timer?

您可能想研究使用

Looks like processRequest() doesn't actually wait for a response to be ready. When there is no delay in between, response is not yet there (because it takes much more time to produce it than spent in method calls). And processResponse quite reasonably handles this as a timeout.

Look for locks and conditions . Your response needs to wait for the request to complete. If they are threads, your response needs to Join the request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM