in java please Modify “Producer and Consumer Problem” from the lecture note so that it can use all buffer
space, not “buffersize – 1” as in the lecture note. This
1. The user will run the program and will enter two numbers on the command line.
Those numbers will be used for buffersize and counter limit.
2. The main program will then create separate producer and consumer threads.
3. The Producer thread generates a random number through a random number
generator function, inserts it into the buffer, prints the number, and increment
counter.
4. The Consumer thread goes to the buffer, takes a number in the proper order, prints it
out, and increment counter.
5. After the counter reaches its limit, both threads should be terminated and returned to
the main.
6. Main program terminates.
Step by stepSolved in 2 steps
- USE SIMPLE PYTHON CODE TO COMPLETE Basic version with two levels of threads (master and slaves) One master thread aggregates and sums the result of n slave-threads where each slavethread sums a different range of values in an array of 1000 random integers (please program to generate 1000 random integers to populate the array). The number of slave-threads is a parameter which the user can change. For example, if the user chooses 4 slave threads, each slave thread will sum 1000/4 = 250 numbers. If the user chooses 3 slave threads, the first two may each sum 333 numbers and the third slave threadsums the rest 334 numbers. 2) Advanced version with more than two levels of threadsThe master thread creates two slave-threads where each slave-thread is responsible to sum half segment of the array. Each slave thread will fork/spawn two new slave-threads where each new slave-threadsums half of the array segment received by its parent. Each slave thread will return the subtotal to its parent…arrow_forwardScenario: You have been tasked with building a URL file validator for a web crawler. A web crawler is an application that fetches a web page, extracts the URLs present in that page, and then recursively fetches new pages using the extracted URLs. The end goal of a web crawler is to collect text data, images, or other resources present in order to validate resource URLs or hyperlinks on a page. URL validators can be useful to validate if the extracted URL is a valid resource to fetch. In this scenario, you will build a URL validator that checks for supported protocols and file types.arrow_forwardWrite java code to create a thread by (extending), theprogram create 3 thread that displaying “fatmah” and thenumber of thread that is running.Rewrite the above program by implementing the RunnableInterfacearrow_forward
- Modify this threading example to use, exclusively, multiprocessing, instead of threading. import threadingimport time class BankAccount(): def __init__(self, name, balance): self.name = name self.balance = balance def __str__(self): return self.name # These accounts are our shared resourcesaccount1 = BankAccount("account1", 100)account2 = BankAccount("account2", 0) class BankTransferThread(threading.Thread): def __init__(self, sender, receiver, amount): threading.Thread.__init__(self) self.sender = sender self.receiver = receiver self.amount = amount def run(self): sender_initial_balance = self.sender.balance sender_initial_balance -= self.amount # Inserting delay to allow switch between threads time.sleep(0.001) self.sender.balance = sender_initial_balance receiver_initial_balance = self.receiver.balance receiver_initial_balance += self.amount # Inserting delay to allow switch between threads time.sleep(0.001)…arrow_forwardExercise 1: Write a thread class TabPrinter that prints the elements of an array of integers (in one line) every 2 seconds 5 times. Use the way of extending the class thread. Write the main method which creates and starts three threads Printer which will print different arrays of integers. After that it prints "Main won’t wait. Main exits". Modify the above thread program so that you implement the interface Runnable. Make the main thread waiting till all other threads finish execution. ____________________________________________________________________________________________ Exercise 2: Write a thread class TextThread that prints a text every 1 second 10 times. Read the following main class. Try to guess what will be its output. class Test { public static void main(String s[]) throws Exception { TextThread x = new TextThread ("I am thread x"); TextThread y= new TextThread ("I am thread y"); System.out.println("I am Main thread"); } } Write it and execute it. Is the…arrow_forwardLab Activities: Exercise 1: 1) Write a thread class TabPrinter that prints the elements of an array of integers (in one line) every 2 seconds 5 times. Use the way of extending the class thread. Write the main method which creates and starts three threads Printer which will print different arrays of integers. After that it prints "Main won't wait. Main exits". 2) Modify the above thread program so that you implement the interface Runnable. Make the main thread waiting till all other threads finish execution.arrow_forward
- Could you kindly utilize solely my code as I contributed to its development? I emphasize, please utilize only my code.I attached my code below label my code. The question that I need help with: You need to use the pthread for matrix multiplication. Each threadfrom the threadpool should be responsible for computing only a partof the multiplication (partial product as shown in the above picture –all Ti(S) are called a partical product). Your main thread should splitthe matrices accordingly and create the partial data arrays that areneeded to compute each Ti. You must create a unique task with thedata and submit it to the job queue. You can compute the partialproducts concurrently as long as you have threads available in thethreadpool. You have to remove the task the from queue and submitto a thread in the threadpool. You should define the number ofthreads to be 5 and keep it dynamic so that we can test the samecode with a higher or lower number of threads as needed. When allthe…arrow_forwardSubject Name: Advanced Object-Oriented Programming 1. Complete the below given code (1) class NyThread Thread t: Runnable ( MyThread (String n, int pl t (2) (3) : / creates teh Thread t with nane n : // changen the priority to p Syster.out.printin ("Thread "+n+* created with priority "+p): t. (4) : // exexcute the thread t. I // The only abatarct aethed in Runnable public for (int 1=10: 1>=1: 1--) { Syaten.out.prántin ("Thread *t.getName ()+"\e i - "a) : (5) try { (6) :/ ma ke the Thead t eleep to 2 seconds } catch (Exception e) Syater.out.printin ("Exception in Child"): System.out.printin ("Thread "+t. getName ()+" 1s Exiting"): public statie void main (Stringt) arga) { MyThread t1, 12; ti - new MyThread ("R1", 7): t2 = new MyThread ("R1", 3): try ( :// 2 atatements to aake the Threads ti a v2 exit at same time (8) ) catoh (Exception e) ( Syster.out.printin("Exception in main"): System.out.printin ("Thread Main is Exiting"): 1. 2. 3. 4. 6. 7. 8. 5.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education