Skip to content

Commit 5d8581a

Browse files
committed
fixed:pom.xml
Run 'mvn spotless:apply' to fix these violations.
1 parent 23f22a3 commit 5d8581a

File tree

8 files changed

+60
-60
lines changed

8 files changed

+60
-60
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
<module>table-module</module>
232232
<module>template-method</module>
233233
<module>templateview</module>
234-
<module>thread-pool-executor</module>
234+
<module>thread-pool-executor</module>
235235
<module>thread-specific-storage</module>
236236
<module>throttling</module>
237237
<module>tolerant-reader</module>

thread-specific-storage/src/main/java/com/iluwatar/threadspecificstorage/App.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
/**
44
* Application entry point demonstrating the Thread-Specific Storage pattern.
55
*
6-
* <p>This example simulates concurrent request processing for multiple users.
7-
* Each request carries a user token, and user-specific context is managed
8-
* transparently using thread-specific storage.</p>
6+
* <p>This example simulates concurrent request processing for multiple users. Each request carries
7+
* a user token, and user-specific context is managed transparently using thread-specific storage.
98
*/
109
public class App {
1110

@@ -23,11 +22,13 @@ public static void main(String[] args) {
2322
// Simulate tokens for different users
2423
String token = "token::" + (i % 3 + 1); // 3 distinct users
2524

26-
new Thread(() -> {
27-
// Simulate request processing flow
28-
RequestHandler handler = new RequestHandler(proxy, token);
29-
handler.process();
30-
}).start();
25+
new Thread(
26+
() -> {
27+
// Simulate request processing flow
28+
RequestHandler handler = new RequestHandler(proxy, token);
29+
handler.process();
30+
})
31+
.start();
3132

3233
// Slightly stagger request times
3334
try {

thread-specific-storage/src/main/java/com/iluwatar/threadspecificstorage/RequestHandler.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/**
88
* Application Thread
99
*
10-
* <p>Each instance simulates a request-processing thread that uses
11-
* the Thread-Specific Object Proxy to access Thread-Specific Object.
10+
* <p>Each instance simulates a request-processing thread that uses the Thread-Specific Object Proxy
11+
* to access Thread-Specific Object.
1212
*/
1313
@AllArgsConstructor
1414
@Slf4j
@@ -17,11 +17,9 @@ public class RequestHandler {
1717
private final String token;
1818

1919
/**
20-
* Simulated business process:
21-
* 1. Parse userId from token ("Token::userId").
22-
* 2. Store userId in thread-local storage.
23-
* 3. Later, retrieve userId and use it for business logic.
24-
* 4. Finally, clear thread-local to prevent memory leak.
20+
* Simulated business process: 1. Parse userId from token ("Token::userId"). 2. Store userId in
21+
* thread-local storage. 3. Later, retrieve userId and use it for business logic. 4. Finally,
22+
* clear thread-local to prevent memory leak.
2523
*/
2624
public void process() {
2725
LOGGER.info("Start handling request with token: {}", token);

thread-specific-storage/src/main/java/com/iluwatar/threadspecificstorage/UserContextProxy.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,27 @@
33
/**
44
* Thread-Specific Object Proxy
55
*
6-
* <p>The Thread-Specific Object Proxy acts as an intermediary,
7-
* enabling application thread to access and manipulate thread-specific objects simply and securely.
6+
* <p>The Thread-Specific Object Proxy acts as an intermediary, enabling application thread to
7+
* access and manipulate thread-specific objects simply and securely.
88
*/
99
public class UserContextProxy {
1010
/**
11-
* Underlying TSObjectCollection (ThreadLocalMap) managed by JVM.This ThreadLocal acts as the Key for the map.So That there is also no key factory.
11+
* Underlying TSObjectCollection (ThreadLocalMap) managed by JVM.This ThreadLocal acts as the Key
12+
* for the map.So That there is also no key factory.
1213
*/
1314
private static final ThreadLocal<UserContext> userContextHolder = new ThreadLocal<UserContext>();
1415

15-
/**
16-
* Set UserContext for the current thread.
17-
*/
16+
/** Set UserContext for the current thread. */
1817
public static void set(UserContext context) {
1918
userContextHolder.set(context);
2019
}
2120

22-
/**
23-
* Get UserContext for the current thread.
24-
*/
21+
/** Get UserContext for the current thread. */
2522
public static UserContext get() {
2623
return userContextHolder.get();
2724
}
2825

29-
/**
30-
* Clear UserContext to prevent potential memory leaks.
31-
*/
26+
/** Clear UserContext to prevent potential memory leaks. */
3227
public static void clear() {
3328
userContextHolder.remove();
3429
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package com.iluwatar.threadspecificstorage;
22

3-
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
44

55
import java.io.ByteArrayOutputStream;
66
import java.io.PrintStream;
7+
import org.junit.jupiter.api.Test;
78

8-
import static org.junit.jupiter.api.Assertions.assertTrue;
9-
10-
/**
11-
* Tests for APP class
12-
*/
9+
/** Tests for APP class */
1310
class AppTest {
1411
@Test
1512
void testMainMethod() {
@@ -18,7 +15,7 @@ void testMainMethod() {
1815
System.setOut(new PrintStream(outContent));
1916

2017
// Run the main method
21-
App.main(new String[]{});
18+
App.main(new String[] {});
2219

2320
// Give some time for threads to execute
2421
try {
@@ -29,10 +26,11 @@ void testMainMethod() {
2926

3027
// Verify output contains expected log messages
3128
String output = outContent.toString();
32-
assertTrue(output.contains("Start handling request with token"),
29+
assertTrue(
30+
output.contains("Start handling request with token"),
3331
"Should contain request handling start messages");
3432

3533
// Restore system output
3634
System.setOut(System.out);
3735
}
38-
}
36+
}

thread-specific-storage/src/test/java/com/iluwatar/threadspecificstorage/RequestHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.iluwatar.threadspecificstorage;
22

3-
import org.junit.jupiter.api.Test;
4-
53
import static org.junit.jupiter.api.Assertions.*;
64

5+
import org.junit.jupiter.api.Test;
6+
77
class RequestHandlerTest {
88

99
@Test

thread-specific-storage/src/test/java/com/iluwatar/threadspecificstorage/UserContextProxyTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.iluwatar.threadspecificstorage;
22

3+
import static org.junit.jupiter.api.Assertions.*;
4+
35
import org.junit.jupiter.api.AfterEach;
46
import org.junit.jupiter.api.BeforeEach;
57
import org.junit.jupiter.api.Test;
68

7-
import static org.junit.jupiter.api.Assertions.*;
8-
9-
/**
10-
* Tests for UserContextProxy class
11-
*/
9+
/** Tests for UserContextProxy class */
1210
class UserContextProxyTest {
1311

1412
private UserContext userContext;
@@ -28,7 +26,9 @@ void testSetAndGetContext() {
2826
UserContextProxy.set(userContext);
2927
UserContext retrievedContext = UserContextProxy.get();
3028
assertNotNull(retrievedContext, "Retrieved context should not be null");
31-
assertEquals(userContext.getUserId(), retrievedContext.getUserId(),
29+
assertEquals(
30+
userContext.getUserId(),
31+
retrievedContext.getUserId(),
3232
"Retrieved context should have the same userId");
3333
}
3434

@@ -52,17 +52,19 @@ void testThreadIsolation() throws InterruptedException {
5252
UserContext context2 = new UserContext(456L);
5353
UserContextProxy.set(context1);
5454
// Create another thread to set different context
55-
Thread thread = new Thread(() -> {
56-
UserContextProxy.set(context2);
57-
UserContext threadContext = UserContextProxy.get();
58-
assertNotNull(threadContext);
59-
assertEquals(456L, threadContext.getUserId());
60-
});
55+
Thread thread =
56+
new Thread(
57+
() -> {
58+
UserContextProxy.set(context2);
59+
UserContext threadContext = UserContextProxy.get();
60+
assertNotNull(threadContext);
61+
assertEquals(456L, threadContext.getUserId());
62+
});
6163
thread.start();
6264
thread.join();
6365
// Main thread context should remain unchanged
6466
UserContext mainThreadContext = UserContextProxy.get();
6567
assertNotNull(mainThreadContext);
6668
assertEquals(123L, mainThreadContext.getUserId());
6769
}
68-
}
70+
}

thread-specific-storage/src/test/java/com/iluwatar/threadspecificstorage/UserContextTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.iluwatar.threadspecificstorage;
22

3-
import org.junit.jupiter.api.Test;
43
import static org.junit.jupiter.api.Assertions.*;
54

6-
/**
7-
* Tests for UserContext class
8-
*/
5+
import org.junit.jupiter.api.Test;
6+
7+
/** Tests for UserContext class */
98
class UserContextTest {
109

1110
@Test
1211
void testConstructorAndGetUserId() {
1312
Long userId = 123L;
1413
UserContext context = new UserContext(userId);
1514

16-
assertEquals(userId, context.getUserId(), "UserId should match the one provided in constructor");
15+
assertEquals(
16+
userId, context.getUserId(), "UserId should match the one provided in constructor");
1717
}
1818

1919
@Test
@@ -43,9 +43,15 @@ void testEqualsAndHashCode() {
4343
UserContext context3 = new UserContext(456L);
4444

4545
assertEquals(context1, context2, "Objects with same userId should be equal");
46-
assertEquals(context1.hashCode(), context2.hashCode(), "Objects with same userId should have same hashCode");
46+
assertEquals(
47+
context1.hashCode(),
48+
context2.hashCode(),
49+
"Objects with same userId should have same hashCode");
4750

4851
assertNotEquals(context1, context3, "Objects with different userId should not be equal");
49-
assertNotEquals(context1.hashCode(), context3.hashCode(), "Objects with different userId should have different hashCode");
52+
assertNotEquals(
53+
context1.hashCode(),
54+
context3.hashCode(),
55+
"Objects with different userId should have different hashCode");
5056
}
51-
}
57+
}

0 commit comments

Comments
 (0)