Create a new Java project called usernamePart4 in NetBeans. In my case the project would be called rghanbarPart4.

Write a program that uses 4 threads to print out 4 car makes (Toyota, Hyundai, Jeep, Audi) in the console, in parallel, 20 times each make. NOTE: you will not receive any marks if your program does not use threads.

  • Use two different ways to create the threads: by using the Thread class, and by using the Runnable interface
  • Set different priority to each thread (maximum, normal, minimum)
  • Write the code to put the threads to sleep for 100 milliseconds each time a care make is printed to the console

Use of thread pools:

  • Create a fixed thread pool that returns a thread pool with a maximum of 3 threads
  • Write the code to shut down the fixed thread pool after current tasks are complete and return TRUE when shutdown is complete
  • Create a cached thread pool that returns a thread pool that creates new threads as required
  • Write the code to shut down the cached thread pool immediately and return TRUE if all tasks in the cached thread pool have been terminated

Avoiding data corruptions

  • Assume that there is a possibility of data corruption in this program (data corruption may not happen in this program). Write the necessary code to your methods to allow only one thread can execute the code block at one time so that data corruption is prevented. In order to do so, use both thread Synchronisation and explicit lock object techniques separately.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.