CS508 Assignment No 2 2024

Laiba Noor

New member
Email Verified
Problem Statement:

Among several, two key ideas in Java are concurrency and multithreading, which are used to improve performance in multitasking applications and make effective use of system resources.



In order to implement concurrency and multithreading at a basic level, you must create a Java project and meet the necessary requirements.



  • Create a Java project having two files named as “fruitsbasket.java” and “fruitsRunnable.java”. There are three fruits named as; Apple, Guava and Orange in this project.
  • In the “fruitsRunnable.java” file;
  • Write a class named as “fruitsRunnable”.
  • Create a string-type data member as
  • Create three counters for three fruits of type static int named “Count_A”, “Count_G”, “Count_O”.
  • Write a default constructor of this class that initializes data members.
  • Override run () method to create two elements of each thread for fruit in it, also it should print the counter of each fruit and increment the respective counter after execution.
  • Visit for VU Notes
  • In FruitsBasket.java file;
  • Print your Student ID.
  • Inside the main method;
  • Instantiate three objects of the fruitsRunnable class by giving names as “af_runnable”, “gf_runnable”, “and of_runnable”.
  • Create three objects of Thread class “Thread_af”, “Thread_gf”, and “Thread_of” by passing objects of fruitsRunnable.
  • If threads are created successfully then Print the message, “Threads are created successfully”.
  • Call the “fruits_basket” method as defined below.
  • Define a function after the main method, named” fruits_basket” that takes three objects of threads created above as parameters and inside this function;
  • Set the priority of Threads of Apple and Guava as maximum.
  • Set the priority of Thread of Orange as a minimum.
  • Start all threads.
 

Similar threads

October 2024

Total amount
$156.55
Goal
$400.00
Donation ends:

Staff online

Members online

Forum statistics

Threads
10,647
Messages
28,702
Members
47,986
Latest member
iyed
Top