Closed char1st closed 7 years ago
This is not the problem, but you are using a TimerTask only as a Runnable. You would normally use it with a java.util.Timer. Also, the local device already has a scheduled executor, so you can simplify the async code by doing this:
localDevice.scheduleWithFixedDelay(() -> {
for (final ObjectIdentifier i : logOids) {
...
}
}, 0, period, unit);
But back to your question. What is the problem you are seeing when you run async?
THX . Please excuse me for my poor English. My problem is When I use the first method , the code lookes like hang at localDevice.send(d, multipleRequest) ,and there is no bacnet package send to remoteDevice show in the wireshark .
It could be that while your async code was running the local device was terminated in the other thread.
I found the local device in the first method is not isInitialized , and had to initialize agine then terminate it in the end. I will use the localDevice.scheduleWithFixedDelay() . My fault .... I terminate the local device at Main in finally block .
I have added a check to ensure that the local device is initialized before it will attempt to send requests.
I want run a periodic task use Timertask and ScheduledExecutorService to run RequestUtils.getProperties , but is not work , and I found there is no request send to remoteDevice.
What is the rigth way use RequestUtils in Timertask ?
This under code can work, Why?