In: Computer Science
JAVA
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
public class ThreadCounters { public static void main(String[] args) throws InterruptedException { int lowerLimit = 0; int upperLimit = 20; Thread upCounter = new Thread(new Runnable() { @Override public void run() { for(int i = lowerLimit; i <= upperLimit; i++) { System.out.println(i); } } }); upCounter.start(); upCounter.join(); Thread downCounter = new Thread(new Runnable() { @Override public void run() { for(int i = upperLimit-1; i >= lowerLimit; i--) { System.out.println(i); } } }); downCounter.start(); downCounter.join(); } }