subject

Multithreading. create a multithreaded program that has 3 threads, each one reading a separate file, and each one writing the values read in those files to one of three arrays based on the values read. all values in the files are integers, and the values read (between 1 and 300, inclusive) to are to be placed in the separate arrays as follows: 1) if the value read is from 1 to 100 it gets placed in the first array; 2) if the value read is from 101 to 200 it gets placed in the second array; and 3) if the value is between 201 and 300 it gets placed in the third array. this exercise requires proper synchronization, and requires three classes: arraywriter, multiarray, and a driver class for the main routine. Each of the three arrays must be implemented as a class, MultiArray (NOT an ArrayList), with the following fields: an int writeIndex (the next position to be filled, initialized to 0), and an array of ints with at least 50 integer elements. The MultiArray class must have an add(int) method that is synchronized (either the method must be synchronized or the array it manages must be synchronized); this method adds a passed integer to the array and increments its writeIndex. The ArrayWriter class must implement the Runnable interface, and its job is to is to read an integer from a file, and add it to the appropriate MultiArray. The ArrayWriter constructor must be passed the file (File) and open it, and also be passed the references to the three MultiArrays in which to place the integers read. The run() method reads integers from the file and places in in the appropriate MultiArray by calling the MultiArray's add(int) method. The main routine must: a. prompt the user for three input file names and instantiate three File objects, each with these file names; b. instantiate three MultiArrays; c. instantiate three ArrayWriter objects (passing the constructor the File reference and 3 references to the MultiArrays); d. call the Executors static method newCachedThreadPool, execute each ArrayWriter, and call the shutdown() method; e. wait 1 minute for the three threads to terminate using: try { boolean tasksEnded = executor. awaitTermination (1, Time Unit. MINUTES); if (tasksEnded) { printArray("Array Low", lowArray); printArray("Array Mid", midArray): printArray("Array High", highArray); } else System. out. println("Timed out waiting"); } catch (Exception e) { System. out. printf("Interrupted while waiting: %s\n", e. getMessage(); } f. and implements the printArray() method (above) that displays the each array neatly formatted. Sample data files: File1.txt: 30 130 235 230 240 40 45 140 50 250 150 155 260 160 60 65 70 170 175 270 280 180 185 80 90 190 290 295 20 15 File2.txt: 166 33 133 233 266 243 43 46 143 53 56 253 153 156 263 163 63 73 76 173 273 283 286 183 83 93 96 193 293 16 File3.txt: 37 139 137 237 247 249 47 147 57 59 257 157 159 267 167 67 69 77 177 179 277 287 187 189 87 97 197 297 299 19 Sample output: Enter the first file to scan File 1.txt Enter the second file to scan File2.txt Enter the third file to scan File3.txt Array writer for File 1.txt starts Array writer for File 3.txt starts Array writer for File2.txt starts Array Low 30 37 33 40 43 47 45 46 57 50 53 59 56 60 67 65 63 69 70 73 77 76 80 90 87 97 83 93 20 96 15 19 16 Array Mid 166 130 139 133 137 147 140 143 150 157 155 153 159 156 160 167 163 170 177 175 179 180 173 185 187 189 190 183 197 193 Array High 235 230 237 266 240 247 243 249 250 257 253 260 267 263 270 277 287 273 283 286 290 295 297 299 293

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:30
This technology is used to produce high-quality documents that look good on the computer screen and in print.
Answers: 1
question
Computers and Technology, 22.06.2019 12:30
An atom's diameter is about 0.1 nanometer (1Γ—10-9m), and a human hair is about 1Γ—10-3m. how many times greater is a human hair than an atom's diameter? sorry pushed wronf button but this is math
Answers: 3
question
Computers and Technology, 24.06.2019 01:30
How would you cite different books by the same author on the works cited page? moore, jack h. folk songs and ballads. salem: poetry press, 1999. print. moore, jack h. ballads in poetry – a critical review. dallas: garden books, 1962. print. moore, jack h. folk songs and ballads. salem: poetry press, 1999. print. –––. ballads in poetry – a critical review. dallas: garden books, 1962. print. moore, jack h. ballads in poetry – a critical review. dallas: garden books, 1962. print. moore, jack h. folk songs and ballads. salem: poetry press, 1999. print. moore, jack h. ballads in poetry – a critical review. dallas: garden books, 1962. print. –––. folk songs and ballads. salem: poetry press, 1999. print.
Answers: 2
question
Computers and Technology, 24.06.2019 20:20
Write python code that prompts the user to enter his or her favorite color and assigns the user’s input to a variable named color.
Answers: 1
You know the right answer?
Multithreading. create a multithreaded program that has 3 threads, each one reading a separate file,...
Questions
question
Mathematics, 12.02.2021 21:50
question
Mathematics, 12.02.2021 21:50
question
Mathematics, 12.02.2021 21:50
Questions on the website: 13722361