StartCommand.java
828 Bytes
package com.bsth;
import com.bsth.thread.WaybillCalcThrad;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* 随应用启动运行
* @author PanZhao
*
*/
@Component
public class StartCommand implements CommandLineRunner{
public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(2);
@Autowired
WaybillCalcThrad waybillCalcThrad;
@Override
public void run(String... arg0){
try {
mainServices.scheduleWithFixedDelay(waybillCalcThrad, 60*30, 60*30, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}