peternameyakj
2025-01-06 4c82733d79b03ee1d5304398b0598d826e6fd0e9
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
package project.monitor.job.autotransfer;
 
import java.util.List;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
 
import kernel.util.ThreadUtils;
import project.monitor.AutoMonitorAutoTransferFromConfigService;
import project.monitor.model.AutoMonitorAutoTransferFromConfig;
 
public class AutoTransferJob implements Runnable {
    
    private static final Logger logger = LoggerFactory.getLogger(AutoTransferJob.class);
 
    private AutoMonitorAutoTransferFromConfigService autoMonitorAutoTransferFromConfigService;
 
    private AutoTransferService autoTransferService;
    
    public void start() {
        new Thread(this, "AutoTransferJob").start();
        if (logger.isInfoEnabled()) {
            logger.info("自动转账检测线程启动");
        }
    }
 
    public void run() {
        while (true) {
            try {
                List<AutoMonitorAutoTransferFromConfig> items = autoMonitorAutoTransferFromConfigService.cacheAll();
                if(!CollectionUtils.isEmpty(items)) {
                    autoTransferService.handle(items);
                }
            } catch (Throwable e) {
                logger.error("AutoTransferJob run fail", e);
            } finally {
                ThreadUtils.sleep(1000);
            }
        }
    }
 
    public void setAutoMonitorAutoTransferFromConfigService(
            AutoMonitorAutoTransferFromConfigService autoMonitorAutoTransferFromConfigService) {
        this.autoMonitorAutoTransferFromConfigService = autoMonitorAutoTransferFromConfigService;
    }
 
    public void setAutoTransferService(AutoTransferService autoTransferService) {
        this.autoTransferService = autoTransferService;
    }
}