Final result should be organized as a document which


Program 1

Requirements:

i. You can write an application program which shows process/thread synchronization using:

1. Semaphore
2. Monitor
3. Java Synchronized feautre

ii. Among the above synchronization methods, I hope you would pick one method and apply your application program which requires process/thread synchronization.

iii. In case of Java, please refer to the reference found at the bottom.

iv. Final result should be organized as a document which explains the overview and the structure of your program, real code, execution results (including captured image), and the conclusion including justification of your program, lessons you've learned, comments, etc.

Reference 1: Concurrent/Multithreaded Programming in Java

Java is known as one of the first languages to make multithreading easily available to developers. A thread is assigned code through Thread subclass (start() and run() method) or Runnable interface implementation.

from Java Concurrency/Multithreading by Jakob Jenkov

(1) Critical Section in Java

- Every method declared with the synchronized keyword is a critical section.
- Only one execution thread will access one of the methods of an object declared with the synchronized keyword.
- Only one execution thread will access one of the static method declared with the synchronized keyword, but another thread can access other non-static methods of an object of that class.
- Two threads can access two different synchronized methods if one is static and the other one is not.
- If both methods change the same data, you can have data inconsistency errors.

(2) Bank Synchronization Program

- Description

o Account class : using the synchronized keyword, we guarantee correct access to shared data in
concurrent applications

- tmp, to store the value of the account's balance.

o Bank class : makes 100 calls to the subtractAmount() method that decrements the balance by 100 in
each call.

o Company class : makes 100 calls to the addAmount() method that increments the balance by 1000 in
each call.

o TestBank class

- Remark: Only a thread can access the methods of an object that use the synchronized keyword in their declaration. If a thread (A) is executing a synchronized method and another thread (B) wants to execute other synchronized methods of the same object, it will be blocked until the thread (A) ends.

But if thread (B) has access to different objects of the same class, none of them will be blocked.

from Java 7 Concurrency Cookbook by Javier Fernandez Gonzalez (2012)

(3) Blocking Queues

o Java comes with blocking queue implementations in the java.util.concurrent package.

(4) Thread Pools

o Java comes with built in thread pools in the java.util.concurrent package.

(5) Reference

o Java Concurrency/Multithreading Tutorial by Jakob Jenkov

Program 2

• Requirements:

i. We have learned many kinds of CPU scheduling methods:

1. First-Come, First-Served Scheduling
2. Shortest-Job-First Scheduling
3. Priority Scheduling
4. Round-Robin Scheduling
5. Multilevel Queue Scheduling

ii. Among the above scheduling scheme, I hope you would pick one method and simulate the CPU scheduling procedure.

iii. First, you are supposed to implement CPU scheduler.

iv. Next, you need to populate multiple processes. The processes should be managed by your system from the viewpoint of the Operating Systems. This requires that you maintain the corresponding PCBs. Before the creation of processes, it would be better to design the behavior scenario of each process.

v. The scheduler should show the (concurrent) sequence how the prcesses are selected to run their tasks and release (return) their turn to the other processes.

vi. Most importantly, you have to combine the CPU scheduler with the synchronization mechanism in order to prevent multiple processes from accessing the shared resources including system timer, counter on the queue, etc. The scenario should include a certain situation which show that you included the synchronization scheme on the CPU scheduler.

vii. Final result should be organized as a document which explains the overview and the structure of your program, real code, execution results (including captured image), and the conclusion including justification of your program, lessons you've learned, comments, etc.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Final result should be organized as a document which
Reference No:- TGS01670060

Expected delivery within 24 Hours