John Keiser wrote:

> Hmm.  Reading the appropriate initialization procedure (JVM Spec sections
> 2.16.4 and 2.16.5 at
> http://java.sun.com/docs/books/vmspec/html/Concepts.doc.html#19075), your
> statement is correct.
>
> As far as I can tell, classes have to be initialized on first use, and
> according to the spec, and a constructor cannot actually be *started* unless
> its class is initialized.  (2.16.4 says that a class must be initialized as
> its constructor is invoked, and 2.16.5 says that if the class is
> uninitialized, you try to get a lock on the class before doing
> initialization.
>
> I created a test case of JDK's behavior, though, and it does not do this, so
> perhaps I am reading the req's wrong?

Remember that Java's monitor locks are recursive: a thread can re-aquire a lock
it already holds. The JLS spec on class initialization (S12.4.2) states that if
a class receives a request for initialization when initialization is already in
progress by the same thread, the lock is released and the initialization process
completes without error.

So mutually dependent initializers are allowed, but its up to you to make sure
that they are safe.

regards

  [ bryce ]

Reply via email to