File tree 1 file changed +23
-13
lines changed
dirty-flag/src/main/java/com/iluwatar/dirtyflag
1 file changed +23
-13
lines changed Original file line number Diff line number Diff line change @@ -57,20 +57,30 @@ public class App {
57
57
/** Program execution point. */
58
58
public void run () {
59
59
final var executorService = Executors .newSingleThreadScheduledExecutor ();
60
- executorService .scheduleAtFixedRate (
61
- new Runnable () {
62
- final World world = new World ();
60
+ try {
61
+ executorService .scheduleAtFixedRate (
62
+ new Runnable () {
63
+ final World world = new World ();
63
64
64
- @ Override
65
- public void run () {
66
- var countries = world .fetch ();
67
- LOGGER .info ("Our world currently has the following countries:-" );
68
- countries .stream ().map (country -> "\t " + country ).forEach (LOGGER ::info );
69
- }
70
- },
71
- 0 ,
72
- 15 ,
73
- TimeUnit .SECONDS ); // Run at every 15 seconds.
65
+ @ Override
66
+ public void run () {
67
+ var countries = world .fetch ();
68
+ LOGGER .info ("Our world currently has the following countries:-" );
69
+ countries .stream ().map (country -> "\t " + country ).forEach (LOGGER ::info );
70
+ }
71
+ },
72
+ 0 ,
73
+ 15 ,
74
+ TimeUnit .SECONDS );
75
+
76
+ // Keep running for 45 seconds before shutdown (for demo purpose)
77
+ TimeUnit .SECONDS .sleep (45 );
78
+ } catch (InterruptedException e ) {
79
+ Thread .currentThread ().interrupt ();
80
+ LOGGER .error ("Thread was interrupted" , e );
81
+ } finally {
82
+ executorService .shutdown ();
83
+ }
74
84
}
75
85
76
86
/**
You can’t perform that action at this time.
0 commit comments