Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,30 @@ public class App {
/** Program execution point. */
public void run() {
final var executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(
new Runnable() {
final World world = new World();
try {
executorService.scheduleAtFixedRate(
new Runnable() {
final World world = new World();

@Override
public void run() {
var countries = world.fetch();
LOGGER.info("Our world currently has the following countries:-");
countries.stream().map(country -> "\t" + country).forEach(LOGGER::info);
}
},
0,
15,
TimeUnit.SECONDS); // Run at every 15 seconds.
@Override
public void run() {
var countries = world.fetch();
LOGGER.info("Our world currently has the following countries:-");
countries.stream().map(country -> "\t" + country).forEach(LOGGER::info);
}
},
0,
15,
TimeUnit.SECONDS);

// Keep running for 45 seconds before shutdown (for demo purpose)
TimeUnit.SECONDS.sleep(45);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.error("Thread was interrupted", e);
} finally {
executorService.shutdown();
}
}

/**
Expand Down
Loading