完善退出机制。
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 应用退出服务
|
||||
* @author zhouxiunai
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class ApplicationExitService {
|
||||
|
||||
@Autowired
|
||||
IMsgExchangeService msgExchangeService;
|
||||
|
||||
@PreDestroy
|
||||
public void destory() {
|
||||
msgExchangeService.stop();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD.FLTR;
|
||||
*
|
||||
*/
|
||||
@Service("msgbufferservice")
|
||||
public class FltrSendBufferService implements IFltrSendBufferService {
|
||||
public class FltrSendBufferServiceImpl implements IFltrSendBufferService {
|
||||
private static ConcurrentLinkedQueue<SCHD.FLTR> fltrBuffer = new ConcurrentLinkedQueue<SCHD.FLTR>();
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
public interface IMsgExchangeService {
|
||||
/**
|
||||
* 启动采集线程
|
||||
*/
|
||||
public void start();
|
||||
|
||||
/**
|
||||
* 停止采集线程
|
||||
*/
|
||||
public void stop();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.runner.MsgExchangeRunner;
|
||||
|
||||
@Service
|
||||
public class MsgExchangeServiceImpl implements IMsgExchangeService {
|
||||
|
||||
@Value("${msgExchange.intervalSeconds}")
|
||||
private Long intervalSeconds;
|
||||
|
||||
|
||||
private ScheduledExecutorService scheduledExecutorService = null;
|
||||
|
||||
/**
|
||||
* 启动采集线程
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
//启动消息采集线程
|
||||
if (null == scheduledExecutorService) {
|
||||
scheduledExecutorService = Executors.newScheduledThreadPool(1);
|
||||
scheduledExecutorService.scheduleAtFixedRate(new MsgExchangeRunner(), 0, intervalSeconds , TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止采集线程
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
scheduledExecutorService.shutdown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user