You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
package com.bfd.crawl.ocrhandler.service;
|
|
|
|
|
|
import com.bfd.crawl.ocrhandler.util.QueueUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.boot.ApplicationArguments;
|
|
import org.springframework.boot.ApplicationRunner;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
/**
|
|
* @author:jinming
|
|
* @className:StartServcie
|
|
* @version:1.0
|
|
* @description:
|
|
* @Date:2023/7/31 17:14
|
|
*/
|
|
@Service
|
|
@Slf4j
|
|
public class StartServcie implements ApplicationRunner {
|
|
@Value("${thread.handler}")
|
|
private int handlerNumber;
|
|
@Value("${thread.send}")
|
|
private int sendNumber;
|
|
|
|
@Autowired
|
|
private HandlerService handlerService;
|
|
@Autowired
|
|
private SendService sendService;
|
|
|
|
@Override
|
|
public void run(ApplicationArguments args) throws Exception {
|
|
for (int i = 0; i < handlerNumber; i++) {
|
|
log.info("处理服务线程" + i + "已启动 ");
|
|
handlerService.run();
|
|
}
|
|
for (int i = 0; i < sendNumber; i++) {
|
|
log.info("发送服务线程" + i + "已启动 ");
|
|
sendService.sendToKafka();
|
|
}
|
|
Runnable myRunnable = new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
while (true) {
|
|
log.info("任务队列长度为" + QueueUtil.taskQueue.size());
|
|
log.info("发送队列长度为" + QueueUtil.sendQueue.size());
|
|
try {
|
|
Thread.sleep(10000);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
// 创建一个新的线程,并将Runnable对象传递给Thread构造函数
|
|
Thread myThread = new Thread(myRunnable);
|
|
// 启动线程
|
|
myThread.start();
|
|
|
|
|
|
}
|
|
}
|