Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java - Multi threading: Question: Please see the attached photos below. Please see the Solution class(already defined) and answer accordingly . Thank you. 1. Working

Java - Multi threading:

Question: Please see the attached photos below.

Please see the Solution class(already defined) and answer accordingly .

Thank you.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1. Working with Multithreading You will be given an array of size 300. The name of the array is threadArray, and the index of the array should be referenced by using a variable name i. (Note: The variables threadArray, and i (variable name to access the index of the array) are declared in the predefined class solution). You have to insert elements into the array using three threads by creating three classes, namely Task1, Task2, and Task3, respectively. The values to be inserted into the array are 0,1,2,3,.....299. You should override the run method in the threads. Three integers i, j, and k will be given, representing the number of elements each thread should append inside the given array. Thread one should append 0 to i-1 inside the array, thread two should append i to i+j-1 inside the array, and the third thread should append itj to 299 inside the array. Threads one and two must run simultaneously, and the values of the threads one and two must be inserted inside the indices of the array from 0 to i+j-1 randomly. The third thread should start only after the first two threads have been executed completely. Input Specifications: The first line is an integer representing the number of elements to be inserted inside the array by thread one. The second line is an integer representing the number of elements to be inserted inside the array by thread two. The third line is an integer representing the number of elements to be inserted inside the array by thread three. Output Specifications: The output should be true if the processes are executed in the correct order. Otherwise, it should be false. Sample Input: 80 130 90 Sample Output: true (if both the threads one and two have run simultaneously and the third thread has run after them), or false (if threads one and two have not run simultaneously and thread three has started before threads one and two have got completed). Language Java 8 Autocomplete Ready O 1 import java.util.Scanner; 2 //Write your code here 3 4 v public class Solution { 5 public static final int[] threadArray = new int[300]; 6 public static volatile String i = 0+""; 7 public boolean test() throws InterruptedException 8 { 9 Taski taski = new Taski(); 10 Task2 task2 = new Task2(); 11 Task3 task3 = new Task3(); 12 Thread task2Thread = new Thread (task2); 13 Thread task3Thread = new Thread(task3); 14 taski.start(); 15 task2Thread.start(); 16 taski.join(); 17 task2Thread.join(); 18 task3Thread.start(); 19 int first = Taski.a+Task2.a; 20 int contains Second Thread = Taski.a; 21 String oneAnd Two = ""; 22 String sizeofTaski = ""; 23 for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago