实现ApplicationRunner,并重写run方法即可
@Component
public class InitPortJob implements ApplicationRunner {
private final static Logger logger = LoggerFactory.getLogger(InitPortJob.class);
//数量待调整
public static BlockingQueue<Integer> portQueue = new LinkedBlockingQueue<Integer>(10000);
//@Value("${sip.begin.port}")
private int beginPort=30000;
//@Value("${sip.end.port}")
private int endPort=40000;
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("InitPort Begin MinPort:{};MaxPort:{};",beginPort,endPort);
for (int tempPort = beginPort; tempPort < endPort; tempPort++) {
if(tempPort%2 == 0) {
portQueue.offer(tempPort);
}
}
}
}