summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java
new file mode 100644
index 0000000..3bfe00f
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1606.java
@@ -0,0 +1,31 @@
+/* Listing1606.java */
+
+public class Listing1606
+{
+ public static long testSleep(int millis)
+ {
+ final int MINDURATION = 3000;
+ int cnt = (millis >= MINDURATION ? 1 : MINDURATION/millis);
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < cnt; ++i) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+ }
+ }
+ long end = System.currentTimeMillis();
+ return (end - start) / cnt;
+ }
+
+ public static void main(String[] args)
+ {
+ final int DATA[] = {345, 27, 1, 1962, 2, 8111, 6, 89, 864};
+ for (int i = 0; i < DATA.length; ++i) {
+ System.out.println("Aufruf von sleep(" + DATA[i] + ")");
+ long result = testSleep(DATA[i]);
+ System.out.print(" Ergebnis: " + result);
+ double prec = ((double)result / DATA[i] - 1.0) * 100;
+ System.out.println(" (" + (prec > 0 ? "+": "") + prec + " %)");
+ }
+ }
+} \ No newline at end of file