-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.java
More file actions
51 lines (44 loc) · 1.36 KB
/
Timer.java
File metadata and controls
51 lines (44 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package edu.baylor.ecs.si;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class Timer {
private static Logger logger = Logger.getLogger(Timer.class.getName());
static {
try {
InputStream configFile = Timer.class.getClassLoader().getResourceAsStream("logger.properties");
LogManager.getLogManager().readConfiguration(configFile);
configFile.close();
} catch (IOException ex) {
System.out.println("WARNING: Could not open configuration file");
System.out.println("WARNING: Logging not configured (console output only)");
}
logger.info("starting the app");
}
/*
* Just sleep
*/
private static void method(long time) throws InterruptedException {
Thread.sleep(time);
}
public static long timeMe(long timeToWait) throws TimerException {
Long timeNow = null;
try {
if (timeToWait < 0) {
throw new TimerException("Cannot be less than zero");
}
timeNow = System.currentTimeMillis();
method(timeToWait);
} catch (InterruptedException e) {
logger.severe("InterruptedException rised");
throw new TimerException("Sleep exception", e);
} finally {
if(timeNow != null) {
logger.info("Calling took: "+ (System.currentTimeMillis() - timeNow));
logger.info("* should take: "+ timeToWait);
}
}
return timeNow;
}
}