CS508 Assignment No 2 2024

  • Join us to download any resource for free. You will be able to download or guest post.
    Sign Up Now

Laiba Noor

New member
Jan 17, 2024
3
0
1
Pakistan
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

About us

  • Our community has been around from 2017 and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. Providing Free Resources to help newcomers/startups. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu