描述,业务相关不用理会,只需要看此代码中使用的Executors.newScheduledThreadPool(1),是做了一个项目启动初始化,加载此项,作为启动一个线程池来多少秒延迟多少秒执行一次,这样去处理一些业务,那个MSG是我这边的websocket推送。importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Component;importcom.alibaba.fastjson.JSONObject;importjavax.annotation.PostConstruct;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importjava.util.concurrent.Executors;importjava.util.concurrent.TimeUnit;
@Componentpublic classYTSchedule {private static Logger log = LoggerFactory.getLogger(YTSchedule.class);
@AutowiredprivateCommonConfig config;
@AutowiredprivatePushFaceJob pushface;
@PostConstructpublic voidinit(){if(config.getFaceType() ==1 ||config.getFaceType() ==3){
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() ->{try{
pushface.faceJob();
pushface.pushHitAlertFaceJob();
pushface.pushRealPowerFaceJob();
JSONObject hp= newJSONObject();
hp.put("name","ck");
hp.put("age", 23);
List list= newArrayList();
JSONObject temp= newJSONObject();
temp.put("filter","afads");
JSONObject v= newJSONObject();
v.put("villageCode","310104006001");
temp.put("deep",v);
list.add(temp);
temp.put("filter","12345");
temp= newJSONObject();
list.add(temp);
hp.put("list",list);
Map map= new HashMap<>();
map.put("test", "123545");
hp.put("value",map);
Msg msg= new Msg("hp",hp);
msg.send();
}catch(Exception e){
e.printStackTrace();
}
},20,8,TimeUnit.SECONDS);//待所有服务都启动完成后执行
}
}
}