File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed
src/main/java/com/learn/threading/util Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 1- package com .learn .threading ;
1+ package com .learn .threading . util ;
22
3- public class Incrementer implements Runnable {
3+ public class Incrementer implements Runnable {
44
55 public static int i ;
6- public static void increment (){
6+
7+ public static void increment () {
78 i ++;
89 }
910
1011 @ Override
1112 public void run () {
12- for (int j = 0 ; j <10 ; j ++) {
13+ for (int j = 0 ; j < 10 ; j ++) {
1314 increment ();
1415 }
15- System .out .println ("current value" + i );
16+ System .out .println ("current value" + i );
1617 }
1718
1819}
Original file line number Diff line number Diff line change 1- package com .learn .threading .util ;public class TimerExit {
1+ package com .learn .threading .util ;
2+
3+ import java .util .Date ;
4+ import java .util .Timer ;
5+ import java .util .TimerTask ;
6+
7+ public class TimerExit {
8+
9+ private final long millis ;
10+ Timer timer = new Timer ();
11+ TimerTask timerTask = new TimerTask () {
12+ @ Override
13+ public void run () {
14+ System .out .printf ("Program has been exit after %s milliseconds" , millis );
15+ System .exit (0 );
16+ }
17+ };
18+
19+ public TimerExit (long millis ) {
20+ this .millis = millis ;
21+ }
22+
23+ public void exitProgram () {
24+ timer .schedule (timerTask , new Date (System .currentTimeMillis () + millis ));
25+ }
226}
You can’t perform that action at this time.
0 commit comments