File tree 2 files changed +31
-6
lines changed
src/main/java/com/learn/threading/util
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 ;
2
2
3
- public class Incrementer implements Runnable {
3
+ public class Incrementer implements Runnable {
4
4
5
5
public static int i ;
6
- public static void increment (){
6
+
7
+ public static void increment () {
7
8
i ++;
8
9
}
9
10
10
11
@ Override
11
12
public void run () {
12
- for (int j = 0 ; j <10 ; j ++) {
13
+ for (int j = 0 ; j < 10 ; j ++) {
13
14
increment ();
14
15
}
15
- System .out .println ("current value" + i );
16
+ System .out .println ("current value" + i );
16
17
}
17
18
18
19
}
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
+ }
2
26
}
You can’t perform that action at this time.
0 commit comments