[zeromq-dev] Proper way to shutdown cleanly when blocked [Java bindings]
Jon Rowland
jon.rowland at isam.com
Wed Oct 27 23:38:30 CEST 2010
I didn't think of 2) - that should work perfectly. A poison pill over inproc transport.
Thanks, Jon
-----Original Message-----
From: Martin Sustrik [mailto:sustrik at 250bpm.com]
Sent: 27 October 2010 22:34
To: ZeroMQ development list
Cc: Jon Rowland
Subject: Re: [zeromq-dev] Proper way to shutdown cleanly when blocked [Java bindings]
Hi Jon,
> I'm new to zeromq so please forgive me if this is obvious, but I couldn't find the answer anywhere.
>
> I am using the Java bindings and have a pub/sub socket arrangement. My subscriber listens with recv() in its own thread, blocking when there is no data. My question is how do I cleanly terminate the blocked subscriber when the subscription is no longer needed?
>
> I understand from the docs that a context is thread-safe, but sockets have thread-affinity. So I assume that I shouldn't call close() on the socket from another thread to break the blocked call. The only solution I've found so far is to call term() on the context. This works, but means I have to have a separate context for each subscriber which I don't think is what's intended.
>
> What is the proper pattern for this?
Two use cases:
1. If you are shutting down the process, you should call zmq_term which
will in turn cause all blocking calls to return with ETERM error.
2. If you want to unblock only a single thread, use inproc transport to
send it an "unblock" message. The destination thread can use zmq_poll to
wait for either a new business message or an "unblock" message.
Martin
More information about the zeromq-dev
mailing list