Created
March 9, 2022 16:50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.BrokenBarrierException; | |
import java.util.concurrent.CyclicBarrier; | |
public class Party extends Thread { | |
private int duration; | |
private CyclicBarrier barrier; | |
public Party(int duration, CyclicBarrier barrier, String name) { | |
super(name); | |
this.duration = duration; | |
this.barrier = barrier; | |
} | |
@Override | |
public void run() { | |
try { | |
Thread.sleep(duration); | |
System.out.println(Thread.currentThread().getName() + " is calling await()"); | |
barrier.await(); | |
System.out.println(Thread.currentThread().getName() + " has started running again"); | |
} catch (BrokenBarrierException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment