Removed {TimeOutDuringTesting}

This commit is contained in:
Bruce Eckel 2016-07-07 15:12:55 -06:00
parent 2478dc168b
commit 85ff83410f
10 changed files with 19 additions and 9 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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());

View File

@ -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();

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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();

View File

@ -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());
}
}