Removed {TimeOutDuringTesting}
This commit is contained in:
parent
2478dc168b
commit
85ff83410f
@ -3,6 +3,7 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Cleanup and inheritance
|
// Cleanup and inheritance
|
||||||
|
// {main: polymorphism.Frog}
|
||||||
package polymorphism;
|
package polymorphism;
|
||||||
|
|
||||||
class Characteristic {
|
class Characteristic {
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// How to read from standard input
|
// How to read from standard input
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class Echo {
|
public class Echo {
|
||||||
public static void
|
public static void
|
||||||
main(String[] args) throws IOException {
|
main(String[] args) throws IOException {
|
||||||
|
new TimedAbort(4);
|
||||||
BufferedReader stdin = new BufferedReader(
|
BufferedReader stdin = new BufferedReader(
|
||||||
new InputStreamReader(System.in));
|
new InputStreamReader(System.in));
|
||||||
String s;
|
String s;
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Atomic classes are occasionally useful in regular code
|
// Atomic classes are occasionally useful in regular code
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
// {IgnoreOutput} // No output validation
|
// {IgnoreOutput} // No output validation
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class AtomicEvenSupplier extends IntSupplier {
|
public class AtomicEvenSupplier extends IntSupplier {
|
||||||
private AtomicInteger currentEvenValue =
|
private AtomicInteger currentEvenValue =
|
||||||
@ -15,6 +15,7 @@ public class AtomicEvenSupplier extends IntSupplier {
|
|||||||
return currentEvenValue.addAndGet(2);
|
return currentEvenValue.addAndGet(2);
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
EvenChecker.test(new AtomicEvenSupplier());
|
EvenChecker.test(new AtomicEvenSupplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
// (c)2016 MindView LLC: see Copyright.txt
|
// (c)2016 MindView LLC: see Copyright.txt
|
||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class AtomicityTest implements Runnable {
|
public class AtomicityTest implements Runnable {
|
||||||
private int i = 0;
|
private int i = 0;
|
||||||
@ -15,6 +15,7 @@ public class AtomicityTest implements Runnable {
|
|||||||
evenIncrement();
|
evenIncrement();
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
ExecutorService es = Executors.newCachedThreadPool();
|
ExecutorService es = Executors.newCachedThreadPool();
|
||||||
AtomicityTest at = new AtomicityTest();
|
AtomicityTest at = new AtomicityTest();
|
||||||
es.execute(at);
|
es.execute(at);
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
// (c)2016 MindView LLC: see Copyright.txt
|
// (c)2016 MindView LLC: see Copyright.txt
|
||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
class ExceptionThread2 implements Runnable {
|
class ExceptionThread2 implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
@ -40,6 +40,7 @@ class HandlerThreadFactory implements ThreadFactory {
|
|||||||
|
|
||||||
public class CaptureUncaughtException {
|
public class CaptureUncaughtException {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
ExecutorService exec = Executors.newCachedThreadPool(
|
ExecutorService exec = Executors.newCachedThreadPool(
|
||||||
new HandlerThreadFactory());
|
new HandlerThreadFactory());
|
||||||
exec.execute(new ExceptionThread2());
|
exec.execute(new ExceptionThread2());
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// (c)2016 MindView LLC: see Copyright.txt
|
// (c)2016 MindView LLC: see Copyright.txt
|
||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
// (Behavior may have changed in Java 8)
|
// (Behavior may have changed in Java 8)
|
||||||
// Synchronizing blocks instead of entire methods. Also
|
// Synchronizing blocks instead of entire methods. Also
|
||||||
// demonstrates protection of a non-thread-safe class
|
// demonstrates protection of a non-thread-safe class
|
||||||
@ -11,6 +10,7 @@ package threads;
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
class Pair { // Not thread-safe
|
class Pair { // Not thread-safe
|
||||||
private int x, y;
|
private int x, y;
|
||||||
@ -139,6 +139,7 @@ public class CriticalSection {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
PairManager
|
PairManager
|
||||||
pman1 = new PairManager1(),
|
pman1 = new PairManager1(),
|
||||||
pman2 = new PairManager2();
|
pman2 = new PairManager2();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// When threads collide
|
// When threads collide
|
||||||
// {TimeOutDuringTesting}
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class EvenSupplier extends IntSupplier {
|
public class EvenSupplier extends IntSupplier {
|
||||||
private int currentEvenValue = 0;
|
private int currentEvenValue = 0;
|
||||||
@ -14,6 +14,7 @@ public class EvenSupplier extends IntSupplier {
|
|||||||
return currentEvenValue;
|
return currentEvenValue;
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
EvenChecker.test(new EvenSupplier());
|
EvenChecker.test(new EvenSupplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Preventing thread collisions with mutexes
|
// Preventing thread collisions with mutexes
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
// {IgnoreOutput} // No output validation
|
// {IgnoreOutput} // No output validation
|
||||||
import java.util.concurrent.locks.*;
|
import java.util.concurrent.locks.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class MutexEvenSupplier extends IntSupplier {
|
public class MutexEvenSupplier extends IntSupplier {
|
||||||
private int currentEvenValue = 0;
|
private int currentEvenValue = 0;
|
||||||
@ -23,6 +23,7 @@ public class MutexEvenSupplier extends IntSupplier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
EvenChecker.test(new MutexEvenSupplier());
|
EvenChecker.test(new MutexEvenSupplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
// (c)2016 MindView LLC: see Copyright.txt
|
// (c)2016 MindView LLC: see Copyright.txt
|
||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class SettingDefaultHandler {
|
public class SettingDefaultHandler {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
Thread.setDefaultUncaughtExceptionHandler(
|
Thread.setDefaultUncaughtExceptionHandler(
|
||||||
new MyUncaughtExceptionHandler());
|
new MyUncaughtExceptionHandler());
|
||||||
ExecutorService es = Executors.newCachedThreadPool();
|
ExecutorService es = Executors.newCachedThreadPool();
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
// We make no guarantees that this code is fit for any purpose.
|
// We make no guarantees that this code is fit for any purpose.
|
||||||
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
||||||
// Simplifying mutexes with the synchronized keyword
|
// Simplifying mutexes with the synchronized keyword
|
||||||
// {TimeOutDuringTesting}
|
|
||||||
// {IgnoreOutput} // No output validation
|
// {IgnoreOutput} // No output validation
|
||||||
|
import onjava.TimedAbort;
|
||||||
|
|
||||||
public class
|
public class
|
||||||
SynchronizedEvenSupplier extends IntSupplier {
|
SynchronizedEvenSupplier extends IntSupplier {
|
||||||
@ -17,6 +17,7 @@ SynchronizedEvenSupplier extends IntSupplier {
|
|||||||
return currentEvenValue;
|
return currentEvenValue;
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
new TimedAbort(4);
|
||||||
EvenChecker.test(new SynchronizedEvenSupplier());
|
EvenChecker.test(new SynchronizedEvenSupplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user