[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 class BlockedState {
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
Thread t1 = new Thread(new DemoThreadB());
|
Thread t1 = new Thread(new DemoBlockedRunnable());
|
||||||
Thread t2 = new Thread(new DemoThreadB());
|
Thread t2 = new Thread(new DemoBlockedRunnable());
|
||||||
|
|
||||||
t1.start();
|
t1.start();
|
||||||
t2.start();
|
t2.start();
|
||||||
|
@ -15,7 +15,7 @@ public class BlockedState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemoThreadB implements Runnable {
|
class DemoBlockedRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
commonResource();
|
commonResource();
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.baeldung.concurrent.threadlifecycle;
|
||||||
|
|
||||||
public class TimedWaitingState {
|
public class TimedWaitingState {
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
DemoThread obj1 = new DemoThread();
|
DemoTimeWaitingRunnable runnable = new DemoTimeWaitingRunnable();
|
||||||
Thread t1 = new Thread(obj1);
|
Thread t1 = new Thread(runnable);
|
||||||
t1.start();
|
t1.start();
|
||||||
// The following sleep will give enough time for ThreadScheduler
|
// The following sleep will give enough time for ThreadScheduler
|
||||||
// to start processing of thread t1
|
// to start processing of thread t1
|
||||||
|
@ -12,13 +12,14 @@ public class TimedWaitingState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemoThread implements Runnable {
|
class DemoTimeWaitingRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread()
|
||||||
|
.interrupt();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class WaitingState implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
Thread t2 = new Thread(new DemoThreadWS());
|
Thread t2 = new Thread(new DemoWaitingStateRunnable());
|
||||||
t2.start();
|
t2.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -21,7 +21,7 @@ public class WaitingState implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemoThreadWS implements Runnable {
|
class DemoWaitingStateRunnable implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
Loading…
Reference in New Issue