12.4.2
Detailed Initialization Procedure
EXECUTION
class or interface may be requested recursively as part of the initialization of that
class or interface; for example, a variable initializer in class
A
might invoke a
method of an unrelated class
B
, which might in turn invoke a method of class
A
.
The implementation of the Java Virtual Machine is responsible for taking care of
synchronization and recursive initialization by using the following procedure. It
assumes that the
Class
object has already been verified and prepared, and that the
Class
object contains state that indicates one of four situations:
This
Class
object is verified and prepared but not initialized.
This
Class
object is being initialized by some particular thread
T
.
This
Class
object is fully initialized and ready for use.
This
Class
object is in an erroneous state, perhaps because the verification or
preparation step failed, or because initialization was attempted and failed.
The procedure for initializing a class or interface is then as follows:
1. Synchronize ( 14.17) on the
Class
object that represents the class or interface
to be initialized. This involves waiting until the current thread can obtain the
lock for that object ( 17.13).
2. If initialization is in progress for the class or interface by some other thread,
then
wait
( 20.1.6) on this
Class
object (which temporarily releases the
lock). When the current thread awakens from the
wait
, repeat this step.
3. If initialization is in progress for the class or interface by the current thread,
then this must be a recursive request for initialization. Release the lock on the
Class
object and complete normally.
4. If the class or interface has already been initialized, then no further action is
required. Release the lock on the
Class
object and complete normally.
5. If the
Class
object is in an erroneous state, then initialization is not possible.
Release the lock on the
Class
object and throw a
NoClassDefFoundError
.
6. Otherwise, record the fact that initialization of the
Class
object is now in
progress by the current thread and release the lock on the
Class
object.
7. Next, if the
Class
object represents a class rather than an interface, and the
superclass of this class has not yet been initialized, then recursively perform
this entire procedure for the superclass. If necessary, verify and prepare the
superclass first. If the initialization of the superclass completes abruptly
because of a thrown exception, then lock this
Class
object, label it erroneous,
notify all waiting threads ( 20.1.10), release the lock, and complete abruptly,
throwing the same exception that resulted from initializing the superclass.
226
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved