[zeromq-dev] JeroMQ crashes application

Attila-Mihaly Balazs x_at_y_or_z at yahoo.com
Wed Aug 21 09:31:25 CEST 2013


Just my 2c:

Memory barriers are automatically generated by the Java runtime in any 
of these cases:
- synchronizing on the same class instance
- writing a volatile value from one thread and reading it from the other
- using the same instance of classes from java.util.concurrent 
(semaphore, latch, barrier, locks, atomic*) from two different threads

If you're interested in the topic, you should probably look up "safe 
publishing of java objects in multithreaded environment". BTW, accessing 
an ConcurrentLinkedQueue from two threads (one adding and one removing) 
is case 3 from the above list and guarantees the existence of a memory 
barrier.

Regards,
Attila
>
> Michael, this is a common question and a blog explaining your solution 
> would help a lot of people IMO.
>
> Pieter
>
> On Aug 20, 2013 8:41 PM, "Michael Keselman" 
> <michael.keselman at gmail.com <mailto:michael.keselman at gmail.com>> wrote:
>
>     Pieter,
>
>     Java is not well equipped for a memory barrier implementation. I
>     used in-memory queue (java.util.concurrent.ConcurrentLinkedQueue)
>     with a pool of consumers. Each consumer is running in a separate
>     thread with a dedicated socket. The consumer thread reads from the
>     queue and send content to ZMQ. It works very well and doesn't add
>     much overhead. I may explain the implementation in details in a
>     blog if it make sense.
>
>     Thx
>
>
>     On Sun, Aug 18, 2013 at 1:29 AM, Pieter Hintjens <ph at imatix.com
>     <mailto:ph at imatix.com>> wrote:
>
>         On Thu, Aug 15, 2013 at 4:52 PM, Michael Keselman
>         <michael.keselman at gmail.com
>         <mailto:michael.keselman at gmail.com>> wrote:
>
>         > At the moment I solved the problem by implementing a
>         connection pool with a
>         > number of connected sockets.
>
>         Sounds fair; you just want to make sure there is a full memory
>         barrier
>         when switching sockets between threads. (I've no idea how to
>         achieve
>         this in Java, sorry.)
>
>         -Pieter
>         _______________________________________________
>         zeromq-dev mailing list
>         zeromq-dev at lists.zeromq.org <mailto:zeromq-dev at lists.zeromq.org>
>         http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
>
>     -- 
>     -Michael Keselman
>
>     _______________________________________________
>     zeromq-dev mailing list
>     zeromq-dev at lists.zeromq.org <mailto:zeromq-dev at lists.zeromq.org>
>     http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

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


More information about the zeromq-dev mailing list