I implemented a subscription in my Java application. When adding a new subscriber, the application creates a new task (a class that implements Runnable to run in a separate thread), and is added to the ExecutorService as:
public void Subscribe() { es_.execute(new Subscriber(this, queueName, handler)); }
An application can register as many subscribers as possible. Now I want to implement something like Unsubscribe so that each subscriber has the opportunity to stop the flow of messages. Here I need a way to stop one of the tasks performed in the ExecutorService . But I do not know how I can do this.
ExecutorService.shutdown() and its variants are not for me: they complete all the tasks, I just want to finish one of them. I am looking for a solution. As simple as possible. Thanks.
maverik
source share