我在我的应用程序上收到此警告。我正在同时阅读大约 30 位读者的 rfidtags。每次有标签进来时,我都会点击数据库查看它是否在那里。我有一个我正在使用的休息 api。所以我使用rest模板来点击rest api。关于如何解决这个问题的任何想法?谢谢!
这是我的一些代码:
private void vehicleRequests(List<Maybevehicle> vehicles){
//process list of unique tags to see if they are in the database and linked to a vehicle
List<Maybevehicle> foundMaybeVehs= new ArrayList<>();
List<Maybevehicle> notFound=new ArrayList<>();
if(!vehicles.isEmpty()){
for (Maybevehicle v: vehicles){
Future<Maybevehicle> r=aService.batchVehTags(v);
try{
Maybevehicle m=r.get(2000, TimeUnit.SECONDS);
if(r.isDone()){
if (!(m.getB().getVin().equals("notindb"))){
foundMaybeVehs.add(m);
}
}
}
}catch(InterruptedException | ExecutionException | TimeoutException e){
}
}
if(!foundMaybeVehs.isEmpty()){
addLocation(foundMaybeVehs);
}
}else{
log.info("no vehicles to check.");
}
}
@Override
public Future<Maybevehicle> batchVehTags(Maybevehicle v) {
Future<Maybevehicle> future=null; …Run Code Online (Sandbox Code Playgroud) 我想使用 TaskExecutor 使用 Spring Boot 运行几个长任务。我想让多个 rfid 阅读器连续运行并获取项目标签。然后我需要使用这些标签来更新数据库。到目前为止,我还没有能够使用 Spring Boot 使任务运行一次以上。这可能吗?
我正在创建一个@Component 阅读器类。创建时,我启动侦听器服务和侦听器以跟踪标签。我有 startMessageService 和 setReaderConfig 方法。第一种方法我启动消息侦听器服务以在阅读器进入时接收带有标签信息的消息。第二种方法设置阅读器自主读取,因此当标签经过阅读器时,阅读器将消息发送到听众和我收到消息。
run 方法基本上让读者在消息进来时继续阅读。但由于某种原因,代码没有按照我想要的方式工作。只要读者有标签,我就会收到一条消息,而我没有。
底部是我的 threadpooltaskexecutor bean。
我不确定我错过了什么。
@Component
@Scope("prototype")
public class AlienReader extends AlienClass1Reader implements
TagTableListener, MessageListener, Runnable{
private String ipaddress;
private int port;
private String username;
private String password;
int serviceport;
public AlienReader(String ipaddress, int port, String username, String pwd,
int serviceport) throws UnknownHostException, AlienReaderException,
InterruptedException{
super(ipaddress, port);
this.ipaddress=ipaddress;
this.port=port;
this.username=username;
this.password=pwd;
this.serviceport=serviceport;
startMessageService();
setReaderConfig();
}
Run Code Online (Sandbox Code Playgroud)
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
ThreadPoolTaskExecutor executor …Run Code Online (Sandbox Code Playgroud)