君子博学而日参省乎己 则知明而行无过矣

博客园 首页 新随笔 联系 订阅 管理
Java代码  收藏代码
  1. public class JiveProperties {  
  2.   
  3.     private static final String LOAD_PROPERTIES = "SELECT name, propValue FROM ofProperty";  
  4.   
  5.     private JiveProperties() {  
  6.         System.out.println("JiveProperties constructor");  
  7.     }  
  8.       
  9.     static {  
  10.         System.out.println("static block");  
  11.     }  
  12.       
  13.     private static class JivePropertyHolder {  
  14.         static {  
  15.             System.out.println("initing1");  
  16.         }  
  17.           
  18.         private static final String LOAD_PROPERTIES = "Inner Static Class...";  
  19.           
  20.         private JivePropertyHolder() {  
  21.             System.out.println("inner class...");  
  22.         }  
  23.           
  24.         private static final JiveProperties instance = new JiveProperties();  
  25.           
  26.         static {  
  27.             System.out.println("initing2");  
  28.         }  
  29.     }  
  30.   
  31.     public static JiveProperties getInstance() {  
  32.         return JivePropertyHolder.instance;  
  33.     }  
  34.   
  35.     public static void main(String[] args) {  
  36.         System.out.println(JiveProperties.JivePropertyHolder.LOAD_PROPERTIES);  
  37.     }  
  38.       
  39. }  

 

结果:

static block
Inner Static Class...

 

因此初步判断是迟加载且是线程安全的(由final保证)

http://dracularking.iteye.com/blog/677801

posted on 2013-11-02 15:49  刺猬的温驯  阅读(109)  评论(0)    收藏  举报