qpgong 发表于 2013-1-26 13:59:17

webservices xfire下 并发出现NullPointerException 异常!

在使用xfire后,在个别服务器上出现webservices挂掉,显示空指针异常的错误信息,如下:
java.lang.NullPointerException

   at org.codehaus.xfire.service.binding.ObjectServiceFactory.isValidMethod(ObjectServiceFactory.java:789)

   at org.codehaus.xfire.service.binding.ObjectServiceFactory.initializeOperations(ObjectServiceFactory.java:759)

   at org.codehaus.xfire.service.binding.ObjectServiceFactory.create(ObjectServiceFactory.java:444)

      at org.codehaus.xfire.spring.ServiceBean.afterPropertiesSet(ServiceBean.java:176)


主要原因是由于由于xfire-all.jar包中,org.codehaus.xfire.service.binding.ObjectServiceFactory类中:
private List serviceConfigurations;
this.serviceConfigurations = new ArrayList();
/*   */   protected boolean isValidMethod(Method method)

/*      */   {

/*786 */   for (Iterator itr = this.serviceConfigurations.iterator(); itr.hasNext(); )

/*      */   {

/*788 */       ServiceConfiguration c = (ServiceConfiguration)itr.next();

/*789 */       Boolean b = c.isOperation(method);

/*790 */       if (b != null) return b.booleanValue();

/*      */   }

/*792 */   return true;

/*      */   }

ArrayList不是线程安全的,导致并发取到null,修改方案:
1. 直接使用 java.util.concurrent.CopyOnWriteArrayList
2. 使用Collections.synchronizedList(new ArrayList())
   这样的话当对list进行迭代时,仍然应该放在同步块中。
建议使用第一种!
页: [1]
查看完整版本: webservices xfire下 并发出现NullPointerException 异常!