CameraThread.java
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.junction.thread;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.junction.cache.CacheUtil;
import com.junction.controller.CameraController;
import com.junction.pojo.CameraPojo;
import com.junction.push.CameraPush;
/**
* @Title CameraThread.java
* @description TODO
* @time 2019年12月16日 上午9:32:43
* @author wuguodong
**/
public class CameraThread {
private final static Logger logger = LoggerFactory.getLogger(CameraThread.class);
public static class MyRunnable implements Runnable {
// 创建线程池
public static ExecutorService es = Executors.newCachedThreadPool();
private CameraPojo cameraPojo;
private Thread nowThread;
public MyRunnable(CameraPojo cameraPojo) {
this.cameraPojo = cameraPojo;
}
// 中断线程
public void setInterrupted(String key) {
CacheUtil.PUSHMAP.get(key).setExitcode(1);
}
@Override
public void run() {
// 直播流
try {
// 获取当前线程存入缓存
nowThread = Thread.currentThread();
CacheUtil.STREATMAP.put(cameraPojo.getToken(), cameraPojo);
// 执行转流推流任务
CameraPush push = new CameraPush(cameraPojo);
CacheUtil.PUSHMAP.put(cameraPojo.getToken(), push);
push.push();
// 清除缓存
CacheUtil.STREATMAP.remove(cameraPojo.getToken());
CameraController.JOBMAP.remove(cameraPojo.getToken());
CacheUtil.PUSHMAP.remove(cameraPojo.getToken());
} catch (Exception e) {
CacheUtil.STREATMAP.remove(cameraPojo.getToken());
CameraController.JOBMAP.remove(cameraPojo.getToken());
CacheUtil.PUSHMAP.remove(cameraPojo.getToken());
}
}
}
}