Q> I basically interrupt the previous thread executing it. Is this good practice in tomcat environment?
A> I think that it is normal while you are satisfied that the HTTP stream is blocked for 10 minutes. This means that no other user will be able to process HTTP requests. Otherwise, create and manage your own thread pool.
Q> Is this good practice in tomcat environment?
A> Interruption Runnable or Callable can be difficult. For example, if your thread is in the middle of an I / O operation, an interrupt may leave the data in a damaged state. Other than that, this is quite normal practice. I also recommend using your own thread pool so that your server performance is predictable.
Can you break your big task down into many small tasks? Keeping conditional and output early can be a good alternative to interruption.
Alternatively, waiting / securing the first task completes the operation, while others just return the same value in your environment? If so, I would prefer that instead of your approach. There LoadingCache from the guava library that does just that.
source share