[zeromq-dev] Interrupt and cleanly exit java application

Mohit Anchlia mohitanchlia at gmail.com
Fri Sep 12 23:28:59 CEST 2014

I am using the following code to connect to a socket, however when I exit
the application not all the threads exit. Lot of the threads are waiting,
Is there a better way to cleanly exit the application?

"Thread-6" prio=10 tid=0x00007f0f043d8800 nid=0xff9 runnable
   java.lang.Thread.State: RUNNABLE
        at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
        at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
        at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:79)
        at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:87)
        - locked <0x0000000093b1f0a8> (a sun.nio.ch.Util$2)
        - locked <0x0000000093b1f098> (a
        - locked <0x0000000093b1efb8> (a sun.nio.ch.EPollSelectorImpl)
        at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:98)
        at zmq.Signaler.wait_event(Signaler.java:135)
        at zmq.Mailbox.recv(Mailbox.java:105)

ZMQ.Socket socket = sockets.get();

*if* (*null* == socket) {

socket = context.socket(ZMQ.*REP*);




 *while* (*true*) {

 // Wait for next request from client (C string)

 *try* {

String request = socket.recvStr(0);


 // Do some 'work'

String response = *null*;

response = doWork(request);

 // Send reply back to client (C string)

socket.send(response, 0);

 } *catch* (ZMQException e) {

*if* (e.getErrorCode() == ZMQ.Error.*ETERM*.getCode()) {

*log*.warn("Exiting", e);



*log*.error("Unable to send request", e);




*public* *void* cleanUp() {

*log*.info("Close Called");

 ZMQ.Socket socket = sockets.get();

*if* (*null* != socket) {




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140912/dde84cba/attachment.htm>

More information about the zeromq-dev mailing list