Question: Lab for Threading This is a basic example for understanding Threading, starting and stopping threads. This is to create a new Java project called MyRunnableProject

Lab for Threading

This is a basic example for understanding Threading, starting and stopping threads.

This is to create a new Java project called MyRunnableProject as following.

  • Create a class called MyCurrentDate that implements Runnable interface or extends Thread, you decide which one you need to use?

  • The MyCurrentDate class displays the current date and time x amount of times, with 100 mil interval - use sleep() method for this interval.

  • Create a class called MyMain, which contans main() method, in which 3 instances of MyCurrentDate threads are created and being run. Keep the references to the instances in an array that you can access by index.

  • Each instance of the Thread will be in an infinite loop, running forever so you need to stop each thread. The stop(), kill() and a few other methods are deprecated (no longer allowed). You need to give the number of the thread that you want to stop in your main method.

    o No for loops, use a while(flag is true) loop. Infinite loop.

o Use an instance field Boolean flag to kill just one of the instances at a time by giving

the index of the instance in the array.

*do it with java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!