StartCommand.java 842 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;


/**
 * 随应用启动运行
 *
 */
@Component
public class StartCommand implements CommandLineRunner{

	public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(2);

	@Autowired
	WaybillCalcThrad waybillCalcThrad;

	@Override
	public void run(String... arg0){
		
		try {
			mainServices.scheduleAtFixedRate(waybillCalcThrad, 10, 24l*60*60, TimeUnit.SECONDS);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}