Unsafe: removing the monitorEnter/monitorExit/tryMonitorEnter methods

Dr Heinz M. Kabutz heinz at javaspecialists.eu
Tue Mar 4 05:10:49 UTC 2014


On 04/03/2014, David Holmes <david.holmes at oracle.com> wrote:
> On 3/03/2014 10:56 PM, David M. Lloyd wrote:
>> Yes, that would necessarily be the contract of a Monitors class, just as
>> it is part of the contract of Lock today.  If your argument is that it
>> shouldn't be allowed because it might be used wrong, we might as well
>> just delete most of the JDK, ReentrantLock included, since it suffers
>> from the exact same potential problem.  The difference is that monitors
>> have a simple API in the form of synchronized that people were in the
>> past and would continue to be free (and recommended) to use.
>
> We should not introduce anything that allows something that was
> guaranteed to be safe by the language, to become unsafe. So I can
> support a call for tryMonitorEnter, but not for explicit enter/exit
> actions.

We'd need the explicit exit of course if we have the tryMonitorEnter.



More information about the core-libs-dev mailing list