Skip to content

Commit 9bdc316

Browse files
authored
refactor: improving code and docs for Atomics
AtomicReferenceArrayExample AtomicReferenceExample AtomicReferenceFieldUpdaterExample OddEvenPrinterExample
1 parent 060b9c6 commit 9bdc316

File tree

4 files changed

+2
-6
lines changed

4 files changed

+2
-6
lines changed

src/main/java/org/alxkm/patterns/atomics/AtomicReferenceArrayExample.java

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* AtomicReferenceArray provides atomic operations on arrays of reference values.
88
*/
99
public class AtomicReferenceArrayExample {
10-
11-
1210
/**
1311
* An AtomicReferenceArray named array is created with an initial size of 3 and populated with initial values.
1412
* The updater thread updates the value at index 1 of the array using the compareAndSet method, which atomically compares the current value with an expected value and sets the new value if the comparison is successful.

src/main/java/org/alxkm/patterns/atomics/AtomicReferenceExample.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public void setData(String data) {
2323
}
2424
}
2525

26-
2726
/**
2827
*
2928
* Demonstrates how AtomicReference ensures atomic updates of a shared reference in a multithreaded environment

src/main/java/org/alxkm/patterns/atomics/AtomicReferenceFieldUpdaterExample.java

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ static class MyClass {
1414
volatile String value;
1515
}
1616

17-
1817
/**
1918
* MyClass is a simple class with a volatile reference field named value.
2019
* An AtomicReferenceFieldUpdater named updater is created for the value field of MyClass.

src/main/java/org/alxkm/patterns/oddevenprinter/OddEvenPrinterExample.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class OddEvenPrinterExample {
1515
* @param args command line arguments (not used)
1616
*/
1717
public static void main(String[] args) {
18-
Thread oddThread = new Thread(() -> printOddNumbers());
19-
Thread evenThread = new Thread(() -> printEvenNumbers());
18+
Thread oddThread = new Thread(OddEvenPrinterExample::printOddNumbers);
19+
Thread evenThread = new Thread(OddEvenPrinterExample::printEvenNumbers);
2020

2121
oddThread.setName("OddThread");
2222
evenThread.setName("EvenThread");

0 commit comments

Comments
 (0)