Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is Java Thread problem. - write two classes: Fruit and FruitDemo Fruit class - Fruit shall be a self-running object (that is, it starts

This is Java Thread problem.

- write two classes: Fruit and FruitDemo

Fruit class - Fruit shall be a self-running object (that is, it starts up an internal thread during construction). - The constructor for Fruit shall take a single argument of type String which is the name of the instance: public Fruit(String name) { //...

- The internal thread for a Fruit instance shall print the name supplied at construction 20 times, each time on a line by itself (System.out.println(name)). Optionally, the internal thread may sleep for a short period of time between printing lines.

FruitDemo class - FruitDemo is run (that is, it has the main() method). - Inside main(), create at least two instances of Fruit each with a different name. - When run each instance shall print 20 lines of output. - Adding Thread.sleep(long) calls inside Fruit will show more clearly that two threads are running at the same time, but as stated earlier, the sleep part is optional.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions