File tree Expand file tree Collapse file tree 6 files changed +14
-58
lines changed
Expand file tree Collapse file tree 6 files changed +14
-58
lines changed Original file line number Diff line number Diff line change @@ -16,26 +16,26 @@ public class Atomicity {
1616 public Atomicity();
1717 Code:
1818 0: aload_0
19- 1: invokespecial #1 // Method
19+ 1: invokespecial #1 // Method
2020java/lang/Object."<init>":()V
2121 4: return
2222 void f1();
2323 Code:
2424 0: aload_0
2525 1: dup
26- 2: getfield #2 // Field i:I
26+ 2: getfield #2 // Field i:I
2727 5: iconst_1
2828 6: iadd
29- 7: putfield #2 // Field i:I
29+ 7: putfield #2 // Field i:I
3030 10: return
3131 void f2();
3232 Code:
3333 0: aload_0
3434 1: dup
35- 2: getfield #2 // Field i:I
35+ 2: getfield #2 // Field i:I
3636 5: iconst_3
3737 6: iadd
38- 7: putfield #2 // Field i:I
38+ 7: putfield #2 // Field i:I
3939 10: return
4040}
4141*/
Original file line number Diff line number Diff line change 88public class AtomicityTest implements Runnable {
99 private int i = 0 ;
1010 public int getValue () { return i ; }
11- private synchronized void evenIncrement () { i ++; i ++; }
11+ private synchronized void evenIncrement () {
12+ i ++; i ++;
13+ }
1214 @ Override
1315 public void run () {
1416 while (true )
1517 evenIncrement ();
1618 }
1719 public static void main (String [] args ) {
1820 new TimedAbort (4 );
19- ExecutorService es = Executors .newCachedThreadPool ();
21+ ExecutorService es =
22+ Executors .newCachedThreadPool ();
2023 AtomicityTest at = new AtomicityTest ();
2124 es .execute (at );
2225 while (true ) {
Original file line number Diff line number Diff line change 66// Synchronizing blocks instead of entire methods. Also
77// demonstrates protection of a non-thread-safe class
88// with a thread-safe one.
9- // {java threads .CriticalSection}
10- package threads ;
9+ // {java lowlevel .CriticalSection}
10+ package lowlevel ;
1111import java .util .concurrent .*;
1212import java .util .concurrent .atomic .*;
1313import java .util .*;
Original file line number Diff line number Diff line change 44// Visit http://OnJava8.com for more book information.
55// {ThrowsException} on a multiprocessor machine
66// Using explicit Lock objects to create critical sections
7- // {java threads .ExplicitCriticalSection}
8- package threads ;
7+ // {java lowlevel .ExplicitCriticalSection}
8+ package lowlevel ;
99import java .util .concurrent .locks .*;
1010
1111// Synchronize the entire method:
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments