C:\Users\Morten\Documents\NetBeansProjects\AnothorStartStop\src\anothorstartstop\AnothorStartStop.java |
1
2
package anothorstartstop;
3
4
import java.text.SimpleDateFormat;
5
import java.util.Calendar;
6
7
8
9
10
11
12
13
public class AnothorStartStop
14 {
15
16
private static boolean stop =
false;
17
private static int loop = 0;
18
19
20
21
public AnothorStartStop()
22 {
23
super();
24 }
25
26
27
28
public static void main(String[] args) {
29 args =
new String[4];
30 args[0] =
"start" ;
31
if (
"start".equals(args[0])) {
32
start(args);
33 }
else if (
"stop".equals(args[0])) {
34
stop(args);
35 }
36 }
37
38
39
public static void start(String[] args) {
40 System.
out.println(
"START");
41 System.
out.println(
"The program is only running through 10 loops");
42 System.
out.println(
"Then it Stop.");
43 System.
out.println(
"Thread.sleep(2000)");
44
while (!
stop) {
45
try {
46 Thread.
sleep(2000);
47
loop++;
48 }
catch (InterruptedException e) {
49 System.
err.print(
"InterruptedException "+e);
50 }
51 System.
out.println(
"running: "+
GetCurrentTime());
52
if(
loop > 10)
stop =
true;
53 }
54 System.
out.println(
"Stoped");
55 }
56
57
public static void stop(String[] args) {
58 System.
out.println(
"stop");
59
stop =
true;
60 }
61
62
63
private static String
GetCurrentTime()
64 {
65 String current_time =
new String();
66 Calendar cal = Calendar.
getInstance();
67 SimpleDateFormat format1 =
new SimpleDateFormat(
"kk.mm.ss");
68 current_time = format1.format(cal.getTime());
69 System.
out.println(current_time);
70 current_time.trim();
71
return current_time;
72 }
73
74
public static String
GetDATO()
75 {
76 String current_date =
new String();
77 Calendar cal = Calendar.
getInstance();
78 SimpleDateFormat format1 =
new SimpleDateFormat(
"yyyy-MM-dd");
79 current_date = format1.format(cal.getTime());
80 System.
out.println(current_date);
81 current_date.trim();
82
return current_date;
83 }
84
85 }
86
87