I defined a Future in the following way:
Future<?> future = null;
ExecutorService service = null;
First I used (just playing to get to know the stuff):
future = service.submit(() -> {
for (int i = 0; i < 5; ++i) {
System.out.println("Printing record old: " + i);
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// Ignore
}
}
});
But I really did not like the try catch part, so I rewrote it to:
future = service.submit(() -> {
for (int i = 0; i < 5; ++i) {
System.out.println("Printing record: " + i);
Thread.sleep(5);
}
return "Done";
});
In this way a Callable is used instead of a Runnable and I do not need the catch. But I return an unused value.
Is it OK to do it in this way, or is there a better way?