Chinaunix首页 | 论坛 | 博客
  • 博客访问: 258910
  • 博文数量: 70
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 930
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 12:32
文章存档

2009年(42)

2008年(28)

我的朋友

分类:

2009-04-08 09:44:36

 

:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://itsxhu.blogbus.com/logs/16305783.html

最近在看JVM Specification,看的过程中发现一些以前没有注意到的细节,特意摘录下来。

Java Programming Concept

Fileds:
1、If a final field holds a reference to an object, then the state of the object may be changed by operations on the object, but the field will always refer to the same object.
2、Alternatively, a field may be declared volatile, in which case a thread must reconcile its working copy of the field with the master copy every time it accesses the variable. Moreover, operations on the master copies of one or more volatile variables on behalf of a thread are performed by the main memory in exactly the order that the thread requested.

Mothods:
1、A synchronized method will acquire a monitor lock before it executes. For a class (static) method, the lock associated with the class object for the method's class is used. For an instance method, the lock associated with this (the object for which the method is invoked) is used. The same per-object lock is used by the synchronized statement.

Static Initializers:
1、The static initializers and class variable initializers are executed in textual order. They may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.

Class Loading:
The procedure for initializing a class or interface is then as follows:

   1. Synchronize 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 (§8.13).

   2. If initialization by some other thread is in progress for the class or interface, then wait 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 direct superclass of this class has not yet been initialized, then recursively perform this entire procedure for the uninitialized superclass. If the initialization of the direct superclass completes abruptly because of a thrown exception, then lock this Class object, label it erroneous, notify all waiting threads, release the lock, and complete abruptly, throwing the same exception that resulted from the initializing the superclass.

   8. Next, execute either the class variable initializers and static initializers of the class or the field initializers of the interface, in textual order, as though they were a single block, except that final static variables and fields of interfaces whose values are compile-time constants are initialized first.

   9. If the execution of the initializers completes normally, then lock this Class object, label it fully initialized, notify all waiting threads, release the lock, and complete this procedure normally.

  10. Otherwise, the initializers must have completed abruptly by throwing some exception E. If the class of E is not Error or one of its subclasses, then create a new instance of the class ExceptionInInitializerError, with E as the argument, and use this object in place of E in the following step. But if a new instance of ExceptionInInitializerError cannot be created because an OutOfMemoryError occurs, then instead use an OutOfMemoryError object in place of E in the following step.

  11. Lock the Class object, label it erroneous, notify all waiting threads, release the lock, and complete this procedure abruptly with reason E or its replacement as determined in the previous step. 

阅读(558) | 评论(0) | 转发(0) |
0

上一篇:OutOfMemory

下一篇:JVM大纲

给主人留下些什么吧!~~