Expose Java's built-in monitor synchronization as a JRuby API#6264
Expose Java's built-in monitor synchronization as a JRuby API#6264headius merged 3 commits intojruby:masterfrom
Conversation
I'm not sure why we've never done this before, but since there's
really no way to synchronize against an object's Java monitor from
Ruby this API seems like a gap in JRuby. Here I've added the
following JRuby utility functions:
* JRuby.synchronized(arg) {} which works like Java's synchronized
statement
* JRuby.wait(arg [, millis [, nanos]]) like Object.wait
* JRuby.notify(arg) and notifyAll(arg) like Object.notify[All]
This question came up in the JRuby chat, and it seems like a
useful and appropriate addition to the JRuby module.
875927b to
0a8432c
Compare
|
@headius I thought we had it but I realize now if was the module to allow all methods to synch. Seems like a long overdue feature. |
|
@enebo Yeah, kind of a "duh" moment for me too. The Synchronized module is still out there, but you have to include it into a class or extend it into an object, and then it synchronizes every method call. |
|
indeed very useful, wonder if these should be handling Java wrappers in a special way or not. |
|
@kares No I think your first instinct was right...it should synchronize against the wrapped object. If a user calls synchronize against a Java object, it must actually be locked for other consumers elsewhere in the JVM trying to synchronize against the same object. As far as anyone using JRuby is concerned, there is no wrapper. |
|
I've fixed sync logic for wrapped Java objects. All that remains is writing some tests for this API. |
I'm not sure why we've never done this before, but since there's
really no way to synchronize against an object's Java monitor from
Ruby this API seems like a gap in JRuby. Here I've added the
following JRuby utility functions:
statement
This question came up in the JRuby chat, and it seems like a
useful and appropriate addition to the JRuby module.