Skip to content

Commit ebd816f

Browse files
committed
All book examples resolved and incorporated
1 parent 7265b6a commit ebd816f

18 files changed

Lines changed: 51 additions & 54 deletions

concurrency/BankTellerSimulation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TellerManager implements Runnable {
100100
private Queue<Teller> tellersDoingOtherThings =
101101
new LinkedList<Teller>();
102102
private int adjustmentPeriod;
103-
private static Random rand = new Random(47);
103+
104104
public TellerManager(ExecutorService e,
105105
CustomerLine customers, int adjustmentPeriod) {
106106
exec = e;
@@ -201,4 +201,4 @@ public static void main(String[] args) throws Exception {
201201
Teller 0 terminating
202202
CustomerGenerator interrupted
203203
CustomerGenerator terminating
204-
*///:~
204+
*///:~

concurrency/ExplicitCriticalSection.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//: concurrency/ExplicitCriticalSection.java
2+
// {ThrowsException} on a multiprocessor machine
23
// Using explicit Lock objects to create critical sections.
34
package concurrency;
45
import java.util.concurrent.locks.*;
56

67
// Synchronize the entire method:
78
class ExplicitPairManager1 extends PairManager {
89
private Lock lock = new ReentrantLock();
9-
public synchronized void increment() {
10+
public void increment() {
1011
lock.lock();
1112
try {
1213
p.incrementX();
@@ -31,7 +32,7 @@ public void increment() {
3132
} finally {
3233
lock.unlock();
3334
}
34-
store(temp);
35+
store(temp);
3536
}
3637
}
3738

@@ -42,7 +43,4 @@ public static void main(String[] args) throws Exception {
4243
pman2 = new ExplicitPairManager2();
4344
CriticalSection.testApproaches(pman1, pman2);
4445
}
45-
} /* Output: (Sample)
46-
pm1: Pair: x: 15, y: 15 checkCounter = 174035
47-
pm2: Pair: x: 16, y: 16 checkCounter = 2608588
48-
*///:~
46+
} ///:~

concurrency/PriorityBlockingQueueDemo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,10 @@ public void run() {
108108

109109
public class PriorityBlockingQueueDemo {
110110
public static void main(String[] args) throws Exception {
111-
Random rand = new Random(47);
112111
ExecutorService exec = Executors.newCachedThreadPool();
113112
PriorityBlockingQueue<Runnable> queue =
114113
new PriorityBlockingQueue<Runnable>();
115114
exec.execute(new PrioritizedTaskProducer(queue, exec));
116115
exec.execute(new PrioritizedTaskConsumer(queue));
117116
}
118-
} /* (Execute to see output) *///:~
117+
} /* (Execute to see output) *///:~

containers/MapEntry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public int hashCode() {
2222
}
2323
public boolean equals(Object o) {
2424
if(!(o instanceof MapEntry)) return false;
25-
MapEntry me = (MapEntry)o;
25+
@SuppressWarnings("unchecked")
26+
MapEntry<K,V> me = (MapEntry<K,V>)o;
2627
return
2728
(key == null ?
2829
me.getKey() == null : key.equals(me.getKey())) &&

generics/UseList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//: generics/UseList.java
2-
// {CompileTimeError} (Won't compile)
2+
// {CompileTimeError} (Will not compile)
33
import java.util.*;
44

55
public class UseList<W,T> {
66
void f(List<T> v) {}
77
void f(List<W> v) {}
8-
} ///:~
8+
} ///:~

net/mindview/atunit/AtUnitRemover.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
// www.javassist.org }
88
package net.mindview.atunit;
99
import javassist.*;
10-
import javassist.expr.*;
1110
import javassist.bytecode.*;
1211
import javassist.bytecode.annotation.*;
1312
import java.io.*;
14-
import java.util.*;
1513
import net.mindview.util.*;
1614
import static net.mindview.util.Print.*;
1715

@@ -63,4 +61,4 @@ public void process(File cFile) {
6361
throw new RuntimeException(e);
6462
}
6563
}
66-
} ///:~
64+
} ///:~

net/mindview/atunit/TestProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package net.mindview.atunit;
44
import java.lang.annotation.*;
55

6-
// Both fields and methods may be tagged as properties:
6+
// Both fields and methods can be tagged as properties:
77
@Target({ElementType.FIELD, ElementType.METHOD})
88
@Retention(RetentionPolicy.RUNTIME)
9-
public @interface TestProperty {} ///:~
9+
public @interface TestProperty {} ///:~

net/mindview/util/CountingMapData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CountingMapData
1111
.split(" ");
1212
public CountingMapData(int size) {
1313
if(size < 0) this.size = 0;
14-
this.size = size;
14+
else this.size = size;
1515
}
1616
private static class Entry
1717
implements Map.Entry<Integer,String> {
@@ -46,4 +46,4 @@ public static void main(String[] args) {
4646
}
4747
} /* Output:
4848
{0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 6=G0, 7=H0, 8=I0, 9=J0, 10=K0, 11=L0, 12=M0, 13=N0, 14=O0, 15=P0, 16=Q0, 17=R0, 18=S0, 19=T0, 20=U0, 21=V0, 22=W0, 23=X0, 24=Y0, 25=Z0, 26=A1, 27=B1, 28=C1, 29=D1, 30=E1, 31=F1, 32=G1, 33=H1, 34=I1, 35=J1, 36=K1, 37=L1, 38=M1, 39=N1, 40=O1, 41=P1, 42=Q1, 43=R1, 44=S1, 45=T1, 46=U1, 47=V1, 48=W1, 49=X1, 50=Y1, 51=Z1, 52=A2, 53=B2, 54=C2, 55=D2, 56=E2, 57=F2, 58=G2, 59=H2}
49-
*///:~
49+
*///:~

net/mindview/util/Generated.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//: net/mindview/util/Generated.java
22
package net.mindview.util;
3-
import java.util.*;
43

54
public class Generated {
65
// Fill an existing array:
@@ -15,4 +14,4 @@ public static <T> T[] array(Class<T> type,
1514
(T[])java.lang.reflect.Array.newInstance(type, size);
1615
return new CollectionData<T>(gen, size).toArray(a);
1716
}
18-
} ///:~
17+
} ///:~

net/mindview/util/Print.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public static void print() {
1717
public static void printnb(Object obj) {
1818
System.out.print(obj);
1919
}
20-
// The new Java SE5 printf() (from C):
20+
// The Java SE5 printf() (from C):
2121
public static PrintStream
2222
printf(String format, Object... args) {
2323
return System.out.printf(format, args);
2424
}
25-
} ///:~
25+
} ///:~

0 commit comments

Comments
 (0)