[JAVA-13956] Update/Align code with article
This commit is contained in:
parent
a76b44454a
commit
0ad9dd0fea
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue