Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this assignment is about multi-thread java programming related to operating syst

ID: 3707809 • Letter: T

Question

this assignment is about multi-thread java programming related to operating system, pls attache the code in java.

Thanks in advance:

CSC 4663: Operating Systems Programming Assignment Management of Processes and Resources 1. Assignment Overview In this assignment, you will examine the portion of the kernel that addresses the management of processes and resources. You will develop a system that will allow us to create the data structures to represent processes and resources. We will also implement the operations invoked by processes to manipulate other processes or to request/release various resources. The manager will be tested using presentation shell developed as part of the assignment. This will allow you to test the manager without running the actual processes. Instead, the presentation shell will play the role of both the currently running process; it will accept commands typed in by the user, and will invoke the corresponding function of the manager 2 BASIC PROCESS AND RESOURCE MANAGER 2.1 Process States We assume there are only three process states: ready, running. blocked. The following table lists the possible operations a process may perform and the resulting state transitions Operation old state new state Create Request Relcase Destroy (none) -> ready Running-blocked Blockedready Any-> (none) Scheduler Ready -> running Running --> ready All of the above operations except the Scheduler are invoked directly by the currently running process-the end of cach of the operations. hey represent kernel calls. Thc Scheduler is a function that is invoked automatically at the 2.2 Representation of Processes Each process is represented by a data structure called the process control block (PCB. For this project, we use the following fields of the PCB ID Memo Other Resources Status Creation Tree rio .ID is a unique process identifier by which the process may be referred to by other processes.

Explanation / Answer

import java.awt.*;

import java.awt.event.*;

import java.util.concurrent.ExecutionException;

import javax.swing.*;

public class SwingWorkerCounter extends JPanel {

   // For counter

   private JTextField tfCount;

   private int count = 0;

   // For SwingWorker

   JButton btnStartWorker;   // to start the worker

   private JLabel lblWorker; // for displaying the result

   /** Constructor to setup the GUI components */

   public SwingWorkerCounter () {

      setLayout(new FlowLayout());

      add(new JLabel("Counter"));

      tfCount = new JTextField("0", 10);

      tfCount.setEditable(false);

      add(tfCount);

      JButton btnCount = new JButton("Count");

      add(btnCount);

      btnCount.addActionListener(new ActionListener() {

         @Override

         public void actionPerformed(ActionEvent e) {

            ++count;

            tfCount.setText(count + "");

         }

      });

      /** Create a SwingWorker instance to run a compute-intensive task

          Final result is String, no intermediate result (Void) */

      final SwingWorker<String, Void> worker = new SwingWorker<String, Void>() {

         /** Schedule a compute-intensive task in a background thread */

         @Override

         protected String doInBackground() throws Exception {

            // Sum from 1 to a large n

            long sum = 0;

            for (int number = 1; number < 1000000000; ++number) {

               sum += number;

            }

            return sum + "";

         }

         /** Run in event-dispatching thread after doInBackground() completes */

         @Override

         protected void done() {

            try {

               // Use get() to get the result of doInBackground()

               String result = get();

               // Display the result in the label (run in EDT)

               lblWorker.setText("Result is " + result);

            } catch (InterruptedException e) {

               e.printStackTrace();

            } catch (ExecutionException e) {

               e.printStackTrace();

            }

         }

      };

      btnStartWorker = new JButton("Start Worker");

      add(btnStartWorker);

      btnStartWorker.addActionListener(new ActionListener() {

         @Override

         public void actionPerformed(ActionEvent e) {

            worker.execute();                 // start the worker thread

            lblWorker.setText(" Running...");

            btnStartWorker.setEnabled(false); // Each instance of SwingWorker run once

         }

      });

      lblWorker = new JLabel(" Not started...");

      add(lblWorker);

   }

   /** The entry main() method */

   public static void main(String[] args) {

      // Run the GUI construction in the Event-Dispatching thread for thread-safety

      SwingUtilities.invokeLater(new Runnable() {

         @Override

         public void run() {

            JFrame frame = new JFrame("SwingWorker Test");

            frame.setContentPane(new SwingWorkerCounter());

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            frame.setSize(300, 150);

            frame.setVisible(true);

         }

      });

   }

}