Merge pull request #12768 from panos-kakos/JAVA-13956

[JAVA-13956] Update/Align code with article
This commit is contained in:
Loredana Crusoveanu 2022-10-07 12:32:14 +03:00 committed by GitHub
commit fde21ca87d
6 changed files with 28 additions and 10 deletions

View File

@ -21,6 +21,22 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source.version}</source>
<target>${maven.compiler.target.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source.version>17</maven.compiler.source.version>
<maven.compiler.target.version>17</maven.compiler.target.version>
</properties>
</project>

View File

@ -2,8 +2,8 @@ package com.baeldung.concurrent.threadlifecycle;
public class BlockedState {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(new DemoThreadB());
Thread t2 = new Thread(new DemoThreadB());
Thread t1 = new Thread(new DemoBlockedRunnable());
Thread t2 = new Thread(new DemoBlockedRunnable());
t1.start();
t2.start();
@ -15,7 +15,7 @@ public class BlockedState {
}
}
class DemoThreadB implements Runnable {
class DemoBlockedRunnable implements Runnable {
@Override
public void run() {
commonResource();

View File

@ -2,8 +2,8 @@ package com.baeldung.concurrent.threadlifecycle;
public class TimedWaitingState {
public static void main(String[] args) throws InterruptedException {
DemoThread obj1 = new DemoThread();
Thread t1 = new Thread(obj1);
DemoTimeWaitingRunnable runnable = new DemoTimeWaitingRunnable();
Thread t1 = new Thread(runnable);
t1.start();
// The following sleep will give enough time for ThreadScheduler
// to start processing of thread t1
@ -12,13 +12,14 @@ public class TimedWaitingState {
}
}
class DemoThread implements Runnable {
class DemoTimeWaitingRunnable implements Runnable {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Thread.currentThread()
.interrupt();
e.printStackTrace();
}
}

View File

@ -9,7 +9,7 @@ public class WaitingState implements Runnable {
}
public void run() {
Thread t2 = new Thread(new DemoThreadWS());
Thread t2 = new Thread(new DemoWaitingStateRunnable());
t2.start();
try {
@ -21,7 +21,7 @@ public class WaitingState implements Runnable {
}
}
class DemoThreadWS implements Runnable {
class DemoWaitingStateRunnable implements Runnable {
public void run() {
try {
Thread.sleep(1000);

View File

@ -41,7 +41,6 @@
<module>core-java-collections-maps-2</module>
<module>core-java-collections-maps-3</module>
<module>core-java-collections-maps-5</module>
<module>core-java-concurrency-simple</module>
<module>core-java-concurrency-2</module>
<module>core-java-concurrency-advanced</module>
<module>core-java-concurrency-advanced-2</module>

View File

@ -1169,6 +1169,7 @@
<module>core-java-modules/core-java-collections-set</module>
<module>core-java-modules/core-java-collections-list-4</module>
<module>core-java-modules/core-java-collections-maps-4</module>
<module>core-java-modules/core-java-concurrency-simple</module>
<module>core-java-modules/core-java-date-operations-1</module>
<module>core-java-modules/core-java-datetime-conversion</module>
<module>core-java-modules/core-java-datetime-string</module>
@ -1247,6 +1248,7 @@
<module>core-java-modules/core-java-collections-set</module>
<module>core-java-modules/core-java-collections-list-4</module>
<module>core-java-modules/core-java-collections-maps-4</module>
<module>core-java-modules/core-java-concurrency-simple</module>
<module>core-java-modules/core-java-date-operations-1</module>
<module>core-java-modules/core-java-datetime-conversion</module>
<module>core-java-modules/core-java-datetime-string</module>