| package com.matrix.system.shopXcx.api.action; | 
|   | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.tools.LogUtil; | 
|   | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| public class PayThreadPool { | 
|   | 
|     private static Map<Integer, Object> PAY_WAIT_POOL = new HashMap<>(); | 
|     private static Map<Integer, AjaxResult> PAY_THREAD_MSG = new HashMap<>(); | 
|   | 
|     public static void waitThread(Integer orderId, Object lock) { | 
|         PAY_WAIT_POOL.put(orderId, lock); | 
|         synchronized (lock) { | 
|             try { | 
|                 // 设置线程最多等待15s | 
|                 lock.wait(1000 * 15); | 
|             } catch (InterruptedException e) { | 
|                 LogUtil.debug("线程等待失败", e); | 
|             } | 
|         } | 
|   | 
|     } | 
|   | 
|     public static AjaxResult getThreadResult(Integer orderId) { | 
|         //获取一次后删除结果对象 | 
|         // TODO 需要优化可能存在对象积压过多内存溢出风险 | 
|         return PAY_THREAD_MSG.remove(orderId); | 
|     } | 
|   | 
|     public static void notifyThread(Integer orderId, AjaxResult result) { | 
|         Object lock = PAY_WAIT_POOL.get(orderId); | 
|         if (lock != null) { | 
|             synchronized (lock) { | 
|                 LogUtil.debug("尝试释放锁{}", orderId); | 
|                 PAY_THREAD_MSG.put(orderId, result); | 
|                 PAY_WAIT_POOL.remove(orderId); | 
|                 lock.notifyAll(); | 
|             } | 
|         } | 
|     } | 
|   | 
| } |