Joshua Bloch said:
> I discovered this too, and thought that the spec was completely hosed. On
> further investigation, I found that elsewhere in the spec, it says that the
> thread that runs finalizers "holds no user-visible locks" or some such. I do
> not remember where it says that, but I'm sure that someone else on the list
> remembers.
I do (for the curious). It is in 20.1.11 (chapter 20 describes the Object
class):
> 20.1.11 protected void finalize() throws Throwable
...
> Java does not guarantee which thread will invoke the finalize method for
> any given object. It is guaranteed, however, that the thread that
> invokes finalize will not be holding any user-visible synchronization
> locks when finalize is invoked.
Here is a pointer to it on the web:
http://www.javasoft.com/docs/books/jls/html/javalang.doc1.html#23198
It seems to me that this is probably there not for the sake of the memory
model, but to prevent deadlock. It is still in a counter-intuitive place,
though (it should probably be in 12.6).
Jeremy
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:25 EDT