Skip to content

Commit dc00fc7

Browse files
authoredSep 20, 2024··
refactor: improving correctness of javadocs
1 parent 4cc7664 commit dc00fc7

18 files changed

+24
-23
lines changed
 

‎src/main/java/org/alxkm/antipatterns/forgottensynchronization/CounterExample.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.alxkm.antipatterns.forgottensynchronization;
22

3-
/***
3+
/**
44
*
55
* Forgotten synchronization is a common concurrency issue in Java where a method or block of code that should be synchronized is not,
66
* potentially leading to inconsistent data states or race conditions. Here's an example demonstrating this problem along with a resolution.
@@ -9,7 +9,7 @@
99
* In this example, the increment method and the getCount method are not synchronized,
1010
* leading to potential race conditions when accessed by multiple threads simultaneously.
1111
*
12-
* */
12+
*/
1313
public class CounterExample {
1414
private int counter = 0;
1515

‎src/main/java/org/alxkm/antipatterns/forgottensynchronization/CounterReentrantLockResolution.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import java.util.concurrent.locks.Lock;
44
import java.util.concurrent.locks.ReentrantLock;
55

6-
/***
6+
/**
77
* Instead of using the synchronized keyword, we can use ReentrantLock for more advanced synchronization control.
88
*
99
* Using ReentrantLock provides more flexibility and control over the synchronization process,
1010
* including the ability to use tryLock, lockInterruptibly, and other features not available with the synchronized keyword.
11-
* */
11+
*/
1212
public class CounterReentrantLockResolution {
1313
private int count = 0;
1414
private final Lock lock = new ReentrantLock();

‎src/main/java/org/alxkm/antipatterns/forgottensynchronization/CounterSynchronized.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.alxkm.antipatterns.forgottensynchronization;
22

3-
/***
3+
/**
44
*
55
* To resolve this issue, we need to synchronize the methods to ensure that only one thread can access these critical sections at a time.
66
*
7-
* */
7+
*/
88
public class CounterSynchronized {
99
private int counter = 0;
1010

‎src/main/java/org/alxkm/antipatterns/ignoringinterruptedexception/ProperlyHandlingInterruptedException.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
*
55
* To resolve this issue, the thread should properly handle InterruptedException by either propagating the exception or breaking out of the loop.
66
*
7-
*
87
* In this revised example, the run method handles the
98
* InterruptedException by restoring the interrupt status with Thread.currentThread().interrupt() and breaking out of the loop.
109
* This ensures that the thread stops running as intended.
1110
*
12-
* */
11+
*/
1312
public class ProperlyHandlingInterruptedException implements Runnable {
1413
/**
1514
* The run method performs a long-running task.

‎src/main/java/org/alxkm/antipatterns/improperuseofthreadlocal/ThreadLocalExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* However, the values are not removed after usage, which can lead to memory leaks,
1111
* especially in environments where threads are reused, such as in thread pools.
1212
*
13-
* */
13+
*/
1414
public class ThreadLocalExample {
1515
private static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<>();
1616

‎src/main/java/org/alxkm/antipatterns/lackofthreadsafetyinsingletons/DoubleCheckedLockingSingleton.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* In this version, the volatile keyword ensures visibility of changes to the instance variable across threads,
88
* while double-checked locking minimizes synchronization overhead.
99
*
10-
* */
10+
*/
1111
public class DoubleCheckedLockingSingleton {
1212
private static volatile DoubleCheckedLockingSingleton instance;
1313

‎src/main/java/org/alxkm/antipatterns/lackofthreadsafetyinsingletons/SafeSingleton.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* In this revised example, the getInstance method is synchronized,
88
* ensuring that only one instance is created even when multiple threads access the method simultaneously.
99
*
10-
* */
10+
*/
1111
public class SafeSingleton {
1212
private static SafeSingleton instance;
1313

‎src/main/java/org/alxkm/antipatterns/lockcontention/LockContentionExample.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.alxkm.antipatterns.lockcontention;
22

33
/**
4+
*
45
* Lock contention occurs when multiple threads compete for the same lock, causing some threads to wait while another thread holds the lock.
56
* This can lead to reduced performance due to increased waiting times and underutilized CPU resources.
67
*

‎src/main/java/org/alxkm/antipatterns/lockcontention/LockContentionResolution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* In this revised example, we use AtomicInteger to manage the counter.
1010
* AtomicInteger provides thread-safe operations without the need for explicit synchronization, significantly reducing lock contention.
1111
*
12-
* */
12+
*/
1313
public class LockContentionResolution {
1414
private final AtomicInteger counter = new AtomicInteger();
1515

‎src/main/java/org/alxkm/antipatterns/lockcontention/StampedLockExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* In this version, StampedLock is used to manage the counter.
1010
* StampedLock allows for optimistic reads, which can improve performance by avoiding locks if the data hasn't changed.
1111
*
12-
* */
12+
*/
1313
public class StampedLockExample {
1414
private final StampedLock lock = new StampedLock();
1515
private int counter = 0;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* ensuring that the compound action is performed atomically.
99
* This prevents race conditions and ensures correct results.
1010
*
11-
* */
11+
*/
1212
public class AtomicCompoundActionsExample {
1313
private int counter = 0;
1414

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

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

55
/**
6+
*
67
* Another approach is to use the atomic classes provided by the java.util.concurrent package,
78
* such as AtomicInteger, which provides atomic operations for integers.
89
* <p>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.alxkm.antipatterns.startingthreadinconstructor;
22

3-
/***
3+
/**
44
*
55
* To resolve this issue, start the thread outside the constructor,
66
* ensuring that the object is fully constructed before the thread starts.
77
*
88
* In this revised example, the thread is created in the main method after the object is fully constructed,
99
* ensuring that the thread starts at an appropriate time.
1010
*
11-
* */
11+
*/
1212
public class ThreadStartedOutsideConstructor extends Thread {
1313
private final String message;
1414

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.alxkm.antipatterns.startingthreadinconstructor;
22

3-
/***
3+
/**
44
*
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.
@@ -9,7 +9,7 @@
99
* and a factory method createAndStart to create and start the thread.
1010
* This ensures that the thread starts at an appropriate time and provides better encapsulation of the thread creation logic.
1111
*
12-
* */
12+
*/
1313
public class ThreadUsingFactory {
1414
private final String message;
1515

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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-
* */
13+
*/
1414
public class CorrectUsage implements BaseListUsage<String> {
1515
private final List<String> list = new CopyOnWriteArrayList<>();
1616

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void setData(String data) {
3636
* Both threads run concurrently.
3737
* After both threads have completed, the main thread prints the final state of the shared resource.
3838
*
39-
* */
39+
*/
4040
public static void main(String[] args) {
4141
SharedResource initialResource = new SharedResource("Initial Data");
4242
AtomicReference<SharedResource> atomicReference = new AtomicReference<>(initialResource);

‎src/main/java/org/alxkm/patterns/executors/ScheduledThreadPoolExecutorExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ScheduledThreadPoolExecutorExample {
1717
* Task 3: Executes repeatedly with a fixed delay between termination of one execution and commencement of the next, starting after an initial delay of 2 seconds, with a delay of 3 seconds using scheduleWithFixedDelay().
1818
* Finally, we schedule a task to shut down the executor after 10 seconds using schedule().
1919
*
20-
* */
20+
*/
2121
public static void main(String[] args) {
2222
// Create a ScheduledThreadPoolExecutor with 3 threads
2323
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(3);

‎src/main/java/org/alxkm/patterns/queue/ConcurrentLinkedQueueExample.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Demonstrates the usage of ConcurrentLinkedQueue in a multithreaded environment.
77
*/
88
public class ConcurrentLinkedQueueExample {
9-
/***
9+
/**
1010
*
1111
* We create a ConcurrentLinkedQueue named queue.
1212
* We define two producer threads (producer1 and producer2) that add elements to the queue using the offer() method.
@@ -16,7 +16,7 @@ public class ConcurrentLinkedQueueExample {
1616
* We start all producer and consumer threads concurrently.
1717
* As elements are added and removed from the queue, the producer and consumer threads print messages indicating the elements they add or remove.
1818
*
19-
* */
19+
*/
2020
public static void main(String[] args) {
2121
// Create a ConcurrentLinkedQueue
2222
ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();

0 commit comments

Comments
 (0)
Please sign in to comment.