I have a webservice which calls this method
public void process(Incoming incoming) {
// code to persist data
...
Thread.sleep(20000);
// check persisted data and if status != CANCELLED then process
}
Requirement is that I have to wait 20 seconds (as business has high probability to send cancel request within 20 seconds in which case we should not process).
I understand that Thread.sleep() doesn't even bother the cpu until time's up.
- But concern is, since it is being called from a webservice, these Threads might be from a pool of some sort and might exhaust if lot of requests come?
- Or do new servlet containers automatically create extra threads if exhausted and we can write this kind of code without worrying about these things?
- Does scheduling an asynchronous task which runs after 20 seconds a better option? Here also, we have to have a Thread pool to execute these tasks anyways.