如何解决“已达到 http.client.requests 的最大 URI 标记数”警告?
2022-09-04 01:41:38
我在我的应用上收到此警告。我正在同时阅读大约30个读者的RFIDTAG。每次有标签进来时,我都会点击数据库,看看它是否在那里。我有一个我正在使用的休息 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;
try{
SimpleTaskMaybeveh task=new SimpleTaskMaybeveh(v, appRestTemplate);
future=dbService.submit(task);
}catch(Exception e){
e.printStackTrace();
}
return future;
}
}
public class SimpleTaskMaybeveh implements Callable<Maybevehicle>{
private RestTemplate appRestTemplate;
private Maybevehicle veh;
public SimpleTaskMaybeveh(Maybevehicle veh, RestTemplate appRestTemplate){
this.veh=veh;
this.appRestTemplate=appRestTemplate;
}
@Override
public Maybevehicle call(){
String url="http://url/"+veh.getB().getRfidtag();
String authString= "";
byte[] encodedAuth= Base64.encodeBase64(authString.getBytes(Charset.forName("US-ASCII")));
String authHeader="Basic "+new String(encodedAuth);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.set("Authorization", authHeader);
HttpEntity<Bmwvehiclemain> requestEntity=new HttpEntity <Bmwvehiclemain>(headers);
ResponseEntity<Bmwvehiclemain> results=appRestTemplate.exchange(url, HttpMethod.GET, requestEntity, Bmwvehiclemain.class);
try{
Bmwvehiclemain n=results.getBody();
Maybevehicle d=new Maybevehicle(n,veh.getNewtaglocation());
return d;
}catch(Exception e){
Maybevehicle notveh=new Maybevehicle("notindb");
return notveh;
}
}
}