[zeromq-dev] Java bindings error?

Stuart Halloway stu at thinkrelevance.com
Thu Jun 24 02:23:45 CEST 2010

If the context represents any real resources on the native side, I would recommend going in the opposite direction:

(1) Clients should create and hold the context, and explicitly close it when they are done.

(2) Ditto for sockets (except that creation is via the context).

(3) Neither Context nor Socket should implement finalize.

(4) Instead, they should implement the Closeable interface [1].

How costly is the context? Should it be created once per process? Once per thread? Something else?

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/io/Closeable.html 

> On Wed, Jun 23, 2010 at 5:58 PM, gonzalo diethelm <gdiethelm at dcv.cl> wrote:
>>> I think you are on the right track.  Looking at the native jzmq code,
>>> it appears that transiently using a Context object to construct
>>> Sockets would allow the JVM to "finalize" the Context object while the
>>> application still has a live reference to the Socket object(s).
>>> Something like this:
>> Perhaps we could store a reference to the context from the newly created
>> socket. Would that suffice?
> Ah yes, that's probably much simpler than tackling it inside the native code.
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list