Requirement: In a poller / worker scenario, pollers should stop polling remote service until a worker is available to take the task.
Background: Due to throttling constraints on the number of requests to the remote service, I am trying to segregate polling from the consumers. The constraint here is, that once a task if picked up by a poller, it will timeout if not processed within a certain time. And our consumers can be arbitrarily long running (10s to 10minutes).
Currently looking at the direct solutions, SynchronousQueue seems to be the most simplified approach.
The problem is that if I have 2 pollers and 4 consumers, then while the 4 consumers are processing, the pollers will first pick/poll two tasks from remote, and then wait for consumers to be available. this will cause the 2 tasks to timeout.
Is there a decent workaround this? Or should i be going for lock based mechanism (like: Semaphore) ?