I am getting data from a queue server and I need to process it and send an acknowledgement. Something like this:
while (true) {
queueserver.get.data
If you want the acknowledgment when the worker starts working on the task, you can make a custom ThreadFactory
that sends the acknowledgment from the thread before doing the actual work. OR you can override beforeExecute
of a ThreadPoolExecutor
.
If you want the acknowledgment when a new worker is freed up for a new task, I think you can initialize a ThreadPoolExecutor
with a SynchronousQueue
and a ThreadPoolExecutor.CallerRunsPolicy
, or with your own policy where the caller blocks.