Question

In: Computer Science

Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.

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.

Solutions

Expert Solution

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();
    }

}

Related Solutions

Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
C++Create a C++ 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.
Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
C++ application:Create a C++ 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.For your created code, provide a written analysis of appropriate concepts that could impact your application.Please Specifically, Address: Performance Issues with Concurrency Vulnerabilities Exhibited with use of Strings and Security of the Data Types used.
Create a simple C++ application that will exhibit concurrencyconcepts. Your application should create two threads...
Create a simple C++ 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. For your created code, provide a detailed analysis of appropriate concepts that could impact your application. Specifically, address:Performance issues with concurrencyVulnerabilities exhibited with use of stringsSecurity of the data types exhibited.
Create an application that uses a constructor and two different methods. JAVA
Create an application that uses a constructor and two different methods. JAVA
Using Eclipse to answer this Java question Using the concepts from the Concurrency Basics Tutorial I...
Using Eclipse to answer this Java question Using the concepts from the Concurrency Basics Tutorial I provided in Modules, write a program that consists of two threads. The first is the main thread that every Java application has. The main thread should create a new thread from the Runnable object, MessageLoop, and wait for it to finish. If the MessageLoop thread takes too long to finish, the main thread should interrupt it. Use a variable named maxWaitTime to store the...
Explain the difference between concurrency and parallelism. Using these concepts, discuss how a multi-threaded application can...
Explain the difference between concurrency and parallelism. Using these concepts, discuss how a multi-threaded application can run faster than a single-threaded application on a single-processor machine and on a multi-processor machine.
Using Java create an interactive (the user should be able to input the values) Java Application to process your utility bill for at-least 6 months.
Java ProgrammingAssignment 7.1 (25 points)Using Java create an interactive (the user should be able to input the values) Java Application to process your utility bill for at-least 6 months. Use Class-Object methodology and use single dimensional arrays in your application. Write detailed comments in your program. You should have a two classes (for example, MontlyBill.java & MontlyBillTest.java). You can also be creative and create your “own problem scenario” and come up with your “solution”.Assignment 7.2 (25 points)Use the same program...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Write a complete Java program to create three types of counters as follows: The first counter...
Write a complete Java program to create three types of counters as follows: The first counter increases its value by one. The second counter increases its value by two. The third counter increases its value by three. Please follow these notes: Create one class for all counter types. The name of the class is Three_type_counter. Define a constructor method that initial values for all counters to 7 when the class object created. Create method for each counter as: count1, count2...
Your task is to create a Java application that converts a specified amount of one currency...
Your task is to create a Java application that converts a specified amount of one currency into another currency for a user. The application must meet the following requirements: Upon execution, the application shall display a brief welcome message announcing that the user is running the currency converter application. The application shall allow a user to convert amounts between any two of the following currencies: United States Dollars (USD), British Pounds (GBP), Swiss Francs (CHF), and Indian Rupees (INR). The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT