liurunyu
2024-11-03 3773d0e2d61676ce23901bb79b670691c28c7b04
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/PrefixedDataAvailablePool.java
@@ -6,24 +6,24 @@
public class PrefixedDataAvailablePool {
   
   protected static HashMap<String, List<PrefixedDataAvailable>> pool = new HashMap<String, List<PrefixedDataAvailable>>() ;
   protected static HashMap<String, List<PrefixedDataAvailable>> pool = new HashMap<>() ;
   
   /**
    * 生成对象
    * 线程非安全的,所以用到synchronized
    * @param className
    * @return
    * @param clazz 预处理类
    * @return 预处理类对象
    */
   public static synchronized PrefixedDataAvailable getInstance(Class<?> clazz)throws Exception {
      if(pool == null){
         pool = new HashMap<String, List<PrefixedDataAvailable>>() ;
         pool = new HashMap<>() ;
      }
      String className = clazz.getName() ;
      PrefixedDataAvailable obj = null ;
      
      List<PrefixedDataAvailable> list = pool.get(className) ;
      if(list == null){
         list = new ArrayList<PrefixedDataAvailable>() ;
         list = new ArrayList<>() ;
      }else{
         obj = list.get(0) ;
      }
@@ -33,7 +33,8 @@
         return obj ;
      }else{
         try {
            obj = (PrefixedDataAvailable)clazz.newInstance();
            obj = (PrefixedDataAvailable)clazz.getDeclaredConstructor().newInstance() ;
            //obj = (PrefixedDataAvailable)clazz.newInstance();
         } catch (Exception e) {
            throw new Exception( "由" + className + "生成实例失败!");
         }
@@ -43,10 +44,10 @@
   
   /**
    * 把对象放回池中
    * @param className
    * @return
    * @param clazz 预处理类
    * @param obj  预处理类对象
    */
   public static void freeInstance(Class<?> clazz, PrefixedDataAvailable obj)throws Exception {
   public static void freeInstance(Class<?> clazz, PrefixedDataAvailable obj) {
      if(pool != null){
         String className = clazz.getName() ;
         List<PrefixedDataAvailable> list = pool.get(className) ;