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.

46 lines
1.4 KiB

package com.bx.imserver.task;
2 years ago
import com.bx.imcommon.util.ThreadPoolExecutorFactory;
3 years ago
import com.bx.imserver.netty.IMServerGroup;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
2 years ago
public abstract class AbstractPullMessageTask implements CommandLineRunner {
private static final ScheduledThreadPoolExecutor EXECUTOR_SERVICE = ThreadPoolExecutorFactory.getThreadPoolExecutor();
@Autowired
3 years ago
private IMServerGroup serverGroup;
@Override
public void run(String... args) {
2 years ago
EXECUTOR_SERVICE.execute(new Runnable() {
@SneakyThrows
@Override
public void run() {
try {
if (serverGroup.isReady()) {
pullMessage();
}
2 years ago
} catch (Exception e) {
log.error("任务调度异常", e);
}
if (!EXECUTOR_SERVICE.isShutdown()) {
EXECUTOR_SERVICE.schedule(this,100, TimeUnit.MICROSECONDS);
}
2 years ago
}
});
}
public abstract void pullMessage() throws InterruptedException;
}