Skip to content

Commit d550838

Browse files
committed
Merge branch 'master' into JAVA-47968
# Conflicts: # spring-boot-modules/spring-boot-keycloak-2/pom.xml
2 parents d5b606f + cb091f3 commit d550838

File tree

35 files changed

+1161
-55
lines changed

35 files changed

+1161
-55
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.baeldung.concurrent.busywaiting;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
5+
import static org.junit.jupiter.api.Assertions.fail;
6+
7+
import java.util.concurrent.atomic.AtomicBoolean;
8+
9+
import org.junit.jupiter.api.Test;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
13+
public class BusyWaitingManualTest {
14+
15+
private static final Logger logger = LoggerFactory.getLogger(BusyWaitingManualTest.class);
16+
17+
@Test
18+
void givenWorkerThread_whenBusyWaiting_thenAssertExecutedMultipleTimes() {
19+
AtomicBoolean taskDone = new AtomicBoolean(false);
20+
long counter = 0;
21+
22+
Thread worker = new Thread(() -> {
23+
simulateThreadWork();
24+
taskDone.set(true);
25+
});
26+
27+
worker.start();
28+
29+
while (!taskDone.get()) {
30+
counter++;
31+
}
32+
33+
logger.info("Counter: {}", counter);
34+
assertNotEquals(1, counter);
35+
}
36+
37+
@Test
38+
void givenWorkerThread_whenUsingWaitNotify_thenWaitEfficientlyOnce() {
39+
AtomicBoolean taskDone = new AtomicBoolean(false);
40+
final Object monitor = new Object();
41+
long counter = 0;
42+
43+
Thread worker = new Thread(() -> {
44+
simulateThreadWork();
45+
synchronized (monitor) {
46+
taskDone.set(true);
47+
monitor.notify();
48+
}
49+
});
50+
51+
worker.start();
52+
53+
synchronized (monitor) {
54+
while (!taskDone.get()) {
55+
counter++;
56+
try {
57+
monitor.wait();
58+
} catch (InterruptedException e) {
59+
Thread.currentThread()
60+
.interrupt();
61+
fail("Test case failed due to thread interruption!");
62+
}
63+
}
64+
}
65+
66+
assertEquals(1, counter);
67+
}
68+
69+
private void simulateThreadWork() {
70+
try {
71+
Thread.sleep(500);
72+
} catch (InterruptedException e) {
73+
Thread.currentThread()
74+
.interrupt();
75+
}
76+
}
77+
78+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
plugins {
2+
id 'java-library'
3+
id 'java-test-fixtures'
4+
id 'application'
5+
// Executes smithy-build process to generate client code
6+
id 'software.amazon.smithy.gradle.smithy-base'
7+
}
8+
9+
repositories {
10+
mavenLocal()
11+
mavenCentral()
12+
}
13+
14+
def smithyJavaVersion = project.property('smithyJavaVersion')
15+
16+
// === Code generators ===
17+
dependencies {
18+
smithyBuild "software.amazon.smithy.java.codegen:plugins:${smithyJavaVersion}"
19+
20+
// === Client Dependencies ===
21+
implementation "software.amazon.smithy.java:aws-client-restjson:${smithyJavaVersion}"
22+
23+
// === Server Dependencies ===
24+
implementation "software.amazon.smithy.java:server-netty:${smithyJavaVersion}"
25+
implementation "software.amazon.smithy.java:aws-server-restjson:${smithyJavaVersion}"
26+
27+
// === Test Fixtures ===
28+
testFixturesApi("org.junit.jupiter:junit-jupiter-api:5.5.2")
29+
testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.5.2")
30+
}
31+
32+
// Add generated client source code to the main sourceSet
33+
afterEvaluate {
34+
def clientPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-client-codegen")
35+
sourceSets.main.java.srcDir clientPath
36+
}
37+
38+
// Add generated server source code to the main sourceSet
39+
afterEvaluate {
40+
def serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen")
41+
sourceSets.main.java.srcDir serverPath
42+
}
43+
44+
tasks.named('compileJava') {
45+
dependsOn 'smithyBuild'
46+
}
47+
48+
application {
49+
mainClass = "com.baeldung.smithy.books.server.Main"
50+
}
51+
52+
tasks.test {
53+
useJUnitPlatform()
54+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
smithyGradleVersion=1.3.0
2+
smithyJavaVersion=0.0.1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)