Skip to content

Commit dc00fc7

Browse files
authored
refactor: improving correctness of javadocs
1 parent 4cc7664 commit dc00fc7

File tree

18 files changed

+24
-23
lines changed

18 files changed

+24
-23
lines changed

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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;

0 commit comments

Comments
 (0)