Commit 5bd236fc authored by yanzg's avatar yanzg

修改实例化关系

parent 1fddc0e2
package com.yanzuoguang.media;
import com.yanzuoguang.util.helper.JsonHelper;
import java.util.HashMap;
import java.util.Map;
......@@ -21,7 +23,22 @@ public class MediaCacheLocal implements MediaCacheBase {
*/
@Override
public MediaResVo start(MediaReqVo req, Runnable runnable) {
return null;
// 获取锁
MapLock mapLock = getMapLock(req);
// 锁定缓存对象,防止多人执行
synchronized (mapLock) {
// 读取历史缓存
MediaResVo tempRes = mapLock.res;
// 写入结果到缓存
mapLock.res = JsonHelper.to(req, MediaResVo.class);
// 判断历史缓存的次数,确定是否执行
if (tempRes == null || tempRes.getCount() < 1) {
// 执行时,会开启线程下载视频,并转换为截图文件
runnable.run();
}
// 返回缓存中的结果
return mapLock.res;
}
}
/**
......@@ -32,7 +49,12 @@ public class MediaCacheLocal implements MediaCacheBase {
*/
@Override
public MediaResVo get(MediaReqVo req) {
return null;
// 获取锁
MapLock mapLock = getMapLock(req);
// 锁定缓存对象,防止多人执行
synchronized (mapLock) {
return mapLock.res;
}
}
/**
......@@ -42,7 +64,12 @@ public class MediaCacheLocal implements MediaCacheBase {
*/
@Override
public void sub(MediaResVo res) {
// 获取锁
MapLock mapLock = getMapLock(res);
// 锁定缓存对象,防止多人执行
synchronized (mapLock) {
mapLock.res.subCount();
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment