Future
s should not be ignored JAVA-W1087169 */
170 public void startInvasionRefresh() {
171 executor = Executors.newSingleThreadScheduledExecutor();
172 executor.scheduleAtFixedRate(this::makeRequest, 0, 10, TimeUnit.SECONDS);173 }
174
175 /**
172 */
173 public void startFieldOfficeRefresh() {
174 executor = Executors.newSingleThreadScheduledExecutor();
175 executor.scheduleAtFixedRate(this::makeRequest, 0, 10, TimeUnit.SECONDS);176 }
177
178 /**
146 */
147 public void startDistrictRefresh() {
148 executor = Executors.newSingleThreadScheduledExecutor();
149 executor.scheduleAtFixedRate(this::makeRequest, 0, 30, TimeUnit.SECONDS);150 }
151
152 /**
Always use the value returned by a method with return type Future<T>
.
When a method returns a Future
, it means the result of its computation will only be available at a later time, not immediately. It is possible that the operation may fail with an exception, or may have some useful result.
If the return value is ignored, such data will be lost.
If, however, there truly is no reason to use the result of the future, consider marking this call with a // skipcq: JAVA-W1087
comment to avoid reporting this issue. This issue will also respect suppression via SuppressWarnings("unused")
.
CompletableFuture<String> returnsFuture() {
return someImportantDataInAFuture;
}
void consumer() {
returnsFuture(); // Bad!
}
Even if there is no use for the data, consider adding a handler to process any exceptions that may have occurred during the future's execution.
returnsFuture().handle((v, e) -> {
if (e != null)
logger.error("An error occurred.", e);
});