Skip to content

Commit 205548e

Browse files
authoredSep 10, 2024··
refactor: improving code readability for AtomicCompoundActionsExample, CompletableFutureExample, CorrectUsage, OptimizedUsage, ThreadUsingFactory
1 parent 9bdc316 commit 205548e

File tree

5 files changed

+0
-5
lines changed

5 files changed

+0
-5
lines changed
 

‎src/main/java/org/alxkm/antipatterns/nonatomiccompoundactions/AtomicCompoundActionsExample.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*
55
* To resolve this issue, we can synchronize the method to ensure that the compound action is atomic.
66
*
7-
*
87
* In this revised example, the incrementIfLessThan method is synchronized,
98
* ensuring that the compound action is performed atomically.
109
* This prevents race conditions and ensures correct results.

‎src/main/java/org/alxkm/antipatterns/startingthreadinconstructor/ThreadUsingFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Another approach is to use factory methods to create and start the thread,
66
* ensuring separation of concerns and better control over the thread lifecycle.
77
*
8-
*
98
* In this version, the ThreadUsingFactory class provides a private constructor
109
* and a factory method createAndStart to create and start the thread.
1110
* This ensures that the thread starts at an appropriate time and provides better encapsulation of the thread creation logic.

‎src/main/java/org/alxkm/antipatterns/threadsinsteadoftasks/CompletableFutureExample.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.concurrent.CompletableFuture;
44
import java.util.concurrent.ExecutionException;
55

6-
76
/**
87
* Another approach is to use CompletableFuture,
98
* which is part of the java.util.concurrent package and allows for more flexible task management and asynchronous programming.

‎src/main/java/org/alxkm/antipatterns/usingthreadsafecollectionsincorrectly/CorrectUsage.java

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*
1111
* By synchronizing the addIfAbsent method, we ensure that only one thread can execute it at a time, making the operation atomic.
1212
*
13-
*
1413
* */
1514
public class CorrectUsage implements BaseListUsage<String> {
1615
private final List<String> list = new CopyOnWriteArrayList<>();

‎src/main/java/org/alxkm/antipatterns/usingthreadsafecollectionsincorrectly/OptimizedUsage.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.Collection;
44
import java.util.concurrent.ConcurrentHashMap;
55

6-
76
/**
87
* Another approach is to use a ConcurrentHashMap to achieve atomic check-and-add operations.
98
* The ConcurrentHashMap provides thread-safe methods, simplifying the code.

0 commit comments

Comments
 (0)
Please sign in to comment.