package com.charger.business.acquisition.config;//package com.charger.radar.config;
import com.alibaba.fastjson.JSONObject;
import com.charger.business.acquisition.netty.UDPSend;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Random;
import java.util.UUID;
@Component
@Slf4j
public class AsyncMethod {
@Autowired
public void setUdpSend(UDPSend udpSend) {
this.udpSend = udpSend;
}
private UDPSend udpSend;
//数据发送标志
public static Boolean flag = false;
@Async("executor")
public void test() throws InterruptedException {
//异步要执行的逻辑 在其他地方调用此方法即可实现异步
Random random = new Random();
while (flag) {
Thread.sleep(500);
JSONObject jsonObject = new JSONObject();
jsonObject.put("Idata",random.nextInt(1000 - 100) + 100 + 1 );
jsonObject.put("Odata",random.nextInt(1000 - 100) + 100 + 1);
jsonObject.put("distance", random.nextInt(10000 - 1000) + 1000 + 1);
jsonObject.put("bearing",random.nextInt(360 - 0) + 0 + 1 );
jsonObject.put("pitch",random.nextInt(360 - 0) + 0 + 1);
jsonObject.put("RCS",random.nextInt(1000 - 100) + 100 + 1);
UDPSend.send(JSONObject.toJSONString(jsonObject));
}
}
}
评论0