Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java language please Write a multi-threaded application in which there are three threads. All threads open the same file. The content of this file

in java language please
image text in transcribed
image text in transcribed
image text in transcribed
Write a multi-threaded application in which there are three threads. All threads open the same file. The content of this file is assumed to be lines that each consist of two numbers (you can start by a file that contain the line "O 0"). The first number in each line is the id of the thread that wrote the second number. Each thread performs the following steps: Open the file. Reads the last line in the file Close the file. Increment the second number in the last line by 1. Perform some computation such as finding the sum of the numbers between 1 and 1000000 Open the file. Write the thread id and the incremented number to the end of the file. Close the file. Note that: at the end, all numbers (second number in each line) that are written to the file by all threads should be in sequence. Also, you should figure out what the critical region is, and to prevent the race condition, write your own code using: a. Mutex lock synchronization tool b. Semaphore synchronization tool New Test Document Notepad file Edit Format View Help NHWNPWO OUAWNHO thread : 1 is doing a computation the sum of numbers between 1 and 1000000 s 1783293664 thread: I worked thread : 2 is doing a computation the sum of numbers between 1 and 198880 is : 1783293664 thread : 2 Worked thread : 3 is doing a computation the sum of numbers between 1 and 1000000 1s : 1783293664 thread : 3 Worked C:\Users\Inferno source repos assignment4\Debuglassignment4.exe (process 16272) excited with code . Press any key to close this window

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

Step: 3

blur-text-image

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

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions