java 基础 双重检索

Configuration.getProcessEngine()的代码如下:
/** get the singleton ProcessEngine that is created from the default
* configuration file 'jbpm.cfg.xml'. */ 
public static ProcessEngine getProcessEngine() { 
  if (singleton == null) { 
    synchronized (Configuration.class) { 
      if (singleton == null) { 
        singleton = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine(); 
      } 
    } 
  } 
  return Configuration.singleton; 
}


虽然这一段代码可能会有“双重检查锁定”失败的问题

写代码的时候尽量不要使用双重检查锁定,因为这样的代码不能保证在任何jvm机器上正确执行。

猜你喜欢

转载自mojianpo.iteye.com/blog/1177881