I'm trying to construct 2 methods to sort an array One method will sort an array in ascending order the other method will sort the array in the sending order. To try to implement concurrency of threading. Writen in java.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I'm trying to construct 2 methods to sort an array One method will sort an array in ascending order the other method will sort the array in the sending order. To try to implement concurrency of threading. Writen in java.

11:10
←
package Threads_Synchronization;
import java.util.Random;
import
java.util.concurrent.locks. Lock;
import java.util.concurrent.locks.
ReentrantLock;
X 63%
public class Question3_SortingArrays {
/*
* In this question use mutex lock(s)
or semaphore(s) to enable process
synchronization
*
* Thread 1 and thread 2 share a
single buffer (1D Array), where:
* thread 1 sorts the items of the
buffer in ascending order
* thread 2 sorts the items of the
buffer in descending order
*/
// shared resources between thread 1
and thread 2 are:
// DONOT CHANGE THESE VARIABLE
public static int BufferSize = 10;
//the size of the buffer
public static int buffer[] = new
int [BufferSize]; //the shared buffer
// add any further resources you think
Ascending() and Descending() functions
must share below
O
Transcribed Image Text:11:10 ← package Threads_Synchronization; import java.util.Random; import java.util.concurrent.locks. Lock; import java.util.concurrent.locks. ReentrantLock; X 63% public class Question3_SortingArrays { /* * In this question use mutex lock(s) or semaphore(s) to enable process synchronization * * Thread 1 and thread 2 share a single buffer (1D Array), where: * thread 1 sorts the items of the buffer in ascending order * thread 2 sorts the items of the buffer in descending order */ // shared resources between thread 1 and thread 2 are: // DONOT CHANGE THESE VARIABLE public static int BufferSize = 10; //the size of the buffer public static int buffer[] = new int [BufferSize]; //the shared buffer // add any further resources you think Ascending() and Descending() functions must share below O
11:10
k
// this function simply displays the
content of the shared buffer and which
thread made the call
// DONOT CHANGE THIS FUNCTION
public static void displayStatus() {
if(Thread.current Thread().
getName().equals("ascending"))
System.out.println("Ascending
successfully sorted the array");
else
System.out.println("Descending
successfully sorted the array");
• • * | 63%1
System.out.print(" the " +
Thread.currentThread().getName() +" is
displaying the content of the buffer: ");
for(int i=0; i<BufferSize; i++) {
System.out.print(buffer[i]+"
}
Syste
System.out.println();
// this function sorts the shared
buffer in ascending order
public static void Ascending() {
try {
System.out.println("The
Ascending is trying to sort the shared
buffer");
|||
// Sort the buffer in
ascending order
// Call displayStatus after
you sort and before release the lock
// Implement the Ascending
functionality in the area below
O
Transcribed Image Text:11:10 k // this function simply displays the content of the shared buffer and which thread made the call // DONOT CHANGE THIS FUNCTION public static void displayStatus() { if(Thread.current Thread(). getName().equals("ascending")) System.out.println("Ascending successfully sorted the array"); else System.out.println("Descending successfully sorted the array"); • • * | 63%1 System.out.print(" the " + Thread.currentThread().getName() +" is displaying the content of the buffer: "); for(int i=0; i<BufferSize; i++) { System.out.print(buffer[i]+" } Syste System.out.println(); // this function sorts the shared buffer in ascending order public static void Ascending() { try { System.out.println("The Ascending is trying to sort the shared buffer"); ||| // Sort the buffer in ascending order // Call displayStatus after you sort and before release the lock // Implement the Ascending functionality in the area below O
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Race Condition
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education