WDYT? https://github.com/real-logic/Agrona/issues/82
On Mon, Dec 5, 2016 at 3:24 PM, Guido Medina <oxyg...@gmail.com> wrote: > Don't rethrow the InterruptedException to allow shutdown cycle to start if > main is interrupted (a sort of SIGNAL) > import sun.misc.Signal; > > import java.util.concurrent.CountDownLatch; > > public class SignalBarrier { > > final CountDownLatch latch = new CountDownLatch(1); > > public SignalBarrier() { > Signal.handle(new Signal("INT"), (signal) -> signal()); > } > > public void signal() { > latch.countDown(); > } > > public void await() { > try { > latch.await(); > } catch (InterruptedException ignored) { > } > } > } > > > > On Monday, December 5, 2016 at 3:07:38 PM UTC, Guido Medina wrote: >> >> Cleaner version, you can see now that you can signal() the barrier via >> SIGTERM or manually: >> import sun.misc.Signal; >> >> import java.util.concurrent.CountDownLatch; >> >> public class SignalBarrier { >> >> final CountDownLatch latch = new CountDownLatch(1); >> >> public SignalBarrier() { >> Signal.handle(new Signal("INT"), (signal) -> signal()); >> } >> >> public void signal() { >> latch.countDown(); >> } >> >> public void await() { >> try { >> latch.await(); >> } catch (InterruptedException e) { >> throw new RuntimeException(e); >> } >> } >> } >> >> Notice that CountDownLatch is idempotent once it reaches zero. >> >> HTH, >> >> Guido. >> >> On Monday, December 5, 2016 at 3:00:51 PM UTC, Guido Medina wrote: >>> >>> I have created my own version where I can simply signal if I want to >>> shutdown from another place instead of signalling the process, the >>> following support both: >>> >>> import sun.misc.Signal; >>> >>> import java.util.concurrent.CountDownLatch; >>> >>> public class SignalBarrier { >>> >>> final CountDownLatch latch = new CountDownLatch(1); >>> >>> public SignalBarrier() { >>> Signal.handle(new Signal("INT"), (signal) -> latch.countDown()); >>> } >>> >>> public void signal() { >>> latch.countDown(); >>> } >>> >>> public void await() { >>> try { >>> latch.await(); >>> } catch (InterruptedException e) { >>> throw new RuntimeException(e); >>> } >>> } >>> } >>> >>> >>> >>> On Tuesday, November 29, 2016 at 7:08:34 PM UTC, Marek Żebrowski wrote: >>>> >>>> Thanks for detailed explanation. I'll try to adapt it to my system. >>>> >>> -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/ > current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to a topic in the > Google Groups "Akka User List" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/akka-user/JuJhI6apb00/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > akka-user+unsubscr...@googlegroups.com. > To post to this group, send email to akka-user@googlegroups.com. > Visit this group at https://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscr...@googlegroups.com. To post to this group, send email to akka-user@googlegroups.com. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.