I have a single threaded executor service for fetching some data over the network.
As the user is typing in a search box I am enqueuing possible network tasks. What I want is to cancel all previous requests and only enqueue and immediately run the latest one.
My current approach is to override execute() and submit() methods and clear the queue before calling super.
Any thoughts on this?
Don’t get it, why don’t you save the
Futurereturned on posting a callable to the service, and thencancel()the future if you don’t want it to be executed.e.g.
Cleaner IMO…