1

Wanted to check if thread barrier is the right way to go about solving a problem where you have to poll the DB continuously 2-3 times in specific time intervals for incoming events checking for a trigger and then, eventually timeout in a Spring Integration project.

Also, do we always need 2 threads for thread barrier to work? The suspended thread and the trigger thread.

1 Answers1

0

BarrierMessageHandler is based on the logic like:

Message<?> releaseMessage = syncQueue.poll(this.timeout, TimeUnit.MILLISECONDS);

therefore is blocking the current thread.

So, to release that block you definitely need another thread which offers a value for that SynchronousQueue.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks ! Can I use a thread-barrier to suspend an incoming thread for a predefined wait while I call the DB to check status. If the status from DB is true, it should trigger a release else, wait for the timeout on the barrier and retry. I can tie both the incoming message and the DB result to a correlation. – gautam suddapalli Jul 08 '16 at 14:44
  • Looks like. But consider to use `RequestHandlerRetryAdvice` exactly for the DB call service-activator, not `barrier`. – Artem Bilan Jul 08 '16 at 14:51
  • Hi Artem ! Looks like there is an easier way to do it. We can check DB and use Delayer to delay or push messages based on the DB response. We can save values in the headers and use Router to process based on those flags. – gautam suddapalli Jul 08 '16 at 19:30