ScheduleAtFixedRate is not giving output using Future java 8

Viewed 501

In the following code scheduleAtFixedRate runs endlessly.

So the question is:

Why java provides the infinite thread execution scenarios?

Runnable task1 = () -> System.out.println("Hello Zoo");
Future<?> result = service1.scheduleAtFixedRate(task1, 8, 2, TimeUnit.SECONDS);
System.out.println(result.get());
System.out.println(result.isDone());

The program never prints the output of result.get() which should be null or System.out.println(result.isDone()); which should be 0.

So my point after calling scheduleAtFixedRate the code should be unreachable.

3 Answers
Related