From 85ff83410f82a78791495f17e979652f35be698e Mon Sep 17 00:00:00 2001 From: Bruce Eckel Date: Thu, 7 Jul 2016 15:12:55 -0600 Subject: [PATCH] Removed {TimeOutDuringTesting} --- polymorphism/Frog.java | 1 + standardio/Echo.java | 3 ++- threads/AtomicEvenSupplier.java | 3 ++- threads/AtomicityTest.java | 3 ++- threads/CaptureUncaughtException.java | 3 ++- threads/CriticalSection.java | 3 ++- threads/EvenSupplier.java | 3 ++- threads/MutexEvenSupplier.java | 3 ++- threads/SettingDefaultHandler.java | 3 ++- threads/SynchronizedEvenSupplier.java | 3 ++- 10 files changed, 19 insertions(+), 9 deletions(-) diff --git a/polymorphism/Frog.java b/polymorphism/Frog.java index e29d037a..86ff42ce 100644 --- a/polymorphism/Frog.java +++ b/polymorphism/Frog.java @@ -3,6 +3,7 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // Cleanup and inheritance +// {main: polymorphism.Frog} package polymorphism; class Characteristic { diff --git a/standardio/Echo.java b/standardio/Echo.java index c59ac07c..3fd9f2d7 100644 --- a/standardio/Echo.java +++ b/standardio/Echo.java @@ -3,12 +3,13 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // How to read from standard input -// {TimeOutDuringTesting} import java.io.*; +import onjava.TimedAbort; public class Echo { public static void main(String[] args) throws IOException { + new TimedAbort(4); BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in)); String s; diff --git a/threads/AtomicEvenSupplier.java b/threads/AtomicEvenSupplier.java index d278141c..f1674d37 100644 --- a/threads/AtomicEvenSupplier.java +++ b/threads/AtomicEvenSupplier.java @@ -3,9 +3,9 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // Atomic classes are occasionally useful in regular code -// {TimeOutDuringTesting} // {IgnoreOutput} // No output validation import java.util.concurrent.atomic.*; +import onjava.TimedAbort; public class AtomicEvenSupplier extends IntSupplier { private AtomicInteger currentEvenValue = @@ -15,6 +15,7 @@ public class AtomicEvenSupplier extends IntSupplier { return currentEvenValue.addAndGet(2); } public static void main(String[] args) { + new TimedAbort(4); EvenChecker.test(new AtomicEvenSupplier()); } } diff --git a/threads/AtomicityTest.java b/threads/AtomicityTest.java index e748b304..d7dab569 100644 --- a/threads/AtomicityTest.java +++ b/threads/AtomicityTest.java @@ -2,8 +2,8 @@ // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -// {TimeOutDuringTesting} import java.util.concurrent.*; +import onjava.TimedAbort; public class AtomicityTest implements Runnable { private int i = 0; @@ -15,6 +15,7 @@ public class AtomicityTest implements Runnable { evenIncrement(); } public static void main(String[] args) { + new TimedAbort(4); ExecutorService es = Executors.newCachedThreadPool(); AtomicityTest at = new AtomicityTest(); es.execute(at); diff --git a/threads/CaptureUncaughtException.java b/threads/CaptureUncaughtException.java index 8e8e0211..edc76cad 100644 --- a/threads/CaptureUncaughtException.java +++ b/threads/CaptureUncaughtException.java @@ -2,8 +2,8 @@ // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -// {TimeOutDuringTesting} import java.util.concurrent.*; +import onjava.TimedAbort; class ExceptionThread2 implements Runnable { @Override @@ -40,6 +40,7 @@ class HandlerThreadFactory implements ThreadFactory { public class CaptureUncaughtException { public static void main(String[] args) { + new TimedAbort(4); ExecutorService exec = Executors.newCachedThreadPool( new HandlerThreadFactory()); exec.execute(new ExceptionThread2()); diff --git a/threads/CriticalSection.java b/threads/CriticalSection.java index f2930eee..67f99cd0 100644 --- a/threads/CriticalSection.java +++ b/threads/CriticalSection.java @@ -2,7 +2,6 @@ // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -// {TimeOutDuringTesting} // (Behavior may have changed in Java 8) // Synchronizing blocks instead of entire methods. Also // demonstrates protection of a non-thread-safe class @@ -11,6 +10,7 @@ package threads; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.*; +import onjava.TimedAbort; class Pair { // Not thread-safe private int x, y; @@ -139,6 +139,7 @@ public class CriticalSection { System.exit(0); } public static void main(String[] args) { + new TimedAbort(4); PairManager pman1 = new PairManager1(), pman2 = new PairManager2(); diff --git a/threads/EvenSupplier.java b/threads/EvenSupplier.java index ebdb0ca6..97f792ba 100644 --- a/threads/EvenSupplier.java +++ b/threads/EvenSupplier.java @@ -3,7 +3,7 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // When threads collide -// {TimeOutDuringTesting} +import onjava.TimedAbort; public class EvenSupplier extends IntSupplier { private int currentEvenValue = 0; @@ -14,6 +14,7 @@ public class EvenSupplier extends IntSupplier { return currentEvenValue; } public static void main(String[] args) { + new TimedAbort(4); EvenChecker.test(new EvenSupplier()); } } diff --git a/threads/MutexEvenSupplier.java b/threads/MutexEvenSupplier.java index efc97a22..1b15ba8d 100644 --- a/threads/MutexEvenSupplier.java +++ b/threads/MutexEvenSupplier.java @@ -3,9 +3,9 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // Preventing thread collisions with mutexes -// {TimeOutDuringTesting} // {IgnoreOutput} // No output validation import java.util.concurrent.locks.*; +import onjava.TimedAbort; public class MutexEvenSupplier extends IntSupplier { private int currentEvenValue = 0; @@ -23,6 +23,7 @@ public class MutexEvenSupplier extends IntSupplier { } } public static void main(String[] args) { + new TimedAbort(4); EvenChecker.test(new MutexEvenSupplier()); } } diff --git a/threads/SettingDefaultHandler.java b/threads/SettingDefaultHandler.java index 1de9eb5e..eb027d41 100644 --- a/threads/SettingDefaultHandler.java +++ b/threads/SettingDefaultHandler.java @@ -2,11 +2,12 @@ // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. -// {TimeOutDuringTesting} import java.util.concurrent.*; +import onjava.TimedAbort; public class SettingDefaultHandler { public static void main(String[] args) { + new TimedAbort(4); Thread.setDefaultUncaughtExceptionHandler( new MyUncaughtExceptionHandler()); ExecutorService es = Executors.newCachedThreadPool(); diff --git a/threads/SynchronizedEvenSupplier.java b/threads/SynchronizedEvenSupplier.java index 50c93125..e21698ef 100644 --- a/threads/SynchronizedEvenSupplier.java +++ b/threads/SynchronizedEvenSupplier.java @@ -3,8 +3,8 @@ // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // Simplifying mutexes with the synchronized keyword -// {TimeOutDuringTesting} // {IgnoreOutput} // No output validation +import onjava.TimedAbort; public class SynchronizedEvenSupplier extends IntSupplier { @@ -17,6 +17,7 @@ SynchronizedEvenSupplier extends IntSupplier { return currentEvenValue; } public static void main(String[] args) { + new TimedAbort(4); EvenChecker.test(new SynchronizedEvenSupplier()); } }