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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started