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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:40, wutdmgamerz
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
image
Computers and Technology, 24.06.2019 08:30, daskatingpanda
Formatting rows and columns is similar to cell formatting. in an openoffice calc spreadsheet, you can format data entered into rows and columns with the of the rows and columns options. you can insert rows and columns into, or delete rows and columns from, a spreadsheet. use the insert or delete rows and columns option on the insert tab. alternatively, select the row or column where you want new rows or columns to appear, right-click, and select insert only row or only column options. you can hide or show rows and columns in a spreadsheet. use the hide or show option on the format tab. for example, to hide a row, first select the row, then choose the insert tab, then select the row option, and then select hide. alternatively, you can select the row or columns, right-click, and select the hide or show option. you can adjust the height of rows and width of columns. select row and then select the height option on the format tab. similarly, select column, then select the width option on the format tab. alternatively, you can hold the mouse on the row and column divider, and drag the double arrow to the position. you can also use the autofit option on the table tab to resize rows and columns.
Answers: 1
image
Computers and Technology, 24.06.2019 17:50, veneciaconton347
You will subnet the network address 172.31.103.0/24. the network has the following requirements: · room-114 lan will require 27 host ip addresses · room-279 lan will require 25 host ip addresses · room-312 lan will require 14 host ip addresses · room-407 lan will require 8 host ip addresses how many subnets are needed in the network topology?
Answers: 2
image
Computers and Technology, 25.06.2019 06:20, jorgefrom584
Horseback riders, bicyclists, and skateboarders the rules of right-of-way when they use the road ?
Answers: 1
You know the right answer?
Multithreading. create a multithreaded program that has 3 threads, each one reading a separate file,...

Questions in other subjects:

Konu
Mathematics, 19.11.2020 04:10