Reputation: 43
I started some threads using Executor Service for getting some files from network.I want the Threads to stop execution after some time duration even if their run method is not completed. How to do that? Even executors' shutdown() and awaitTermination(...) methods did not work.
Upvotes: 3
Views: 1348
Reputation: 5112
The simple answer is that you can't. Thread.stop() was deprecated a long (long long) time ago because it was unreliable and was prone to leaving dirty resources behind.
The only other thing you can do, is have your thread pause during its workload and check for exit conditions (like being interrupted, or exceeding some predefined time limit).
Upvotes: 6