Consecutive threads

  • 4
  • Locked
1. In the run method, add a delay of 10 milliseconds after all the actions. Display "Thread interrupted" if the thread is interrupted. 2. Make all the threads run sequentially: first, for thread 1, count down from COUNT to 1; then for thread 2 - from COUNT to 1, etc. Example: #1: 4 #1: 3 ... #1: 1 #
You can't complete this task, because you're not signed in.
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
7 September 2021, 16:38
This "Easy" task was harder than a lot of "Hard" tasks. At least I found it so.
Felix
Level 19
11 April 2020, 00:14
This seems to do the job just fine but isn't validated as correct. Am I wrong with doing it that way?
for (int i = 0; i < COUNT; i++) {
            new SleepingThread() {}.join();
        }
Justin Smith
Level 38 , Greenfield, USA, United States
7 September 2021, 16:41
You can either do
new SleepingThread().join();
which I have seen in some users' solutions, or declare Thread t; earlier in the code and then do:
t = new SleepingThread();
t.join();
I did it the second way because I didn't know we could use a method call the way it is used in the first one.
Santosh Kumar
Level 19 , Gagret, India
1 July 2019, 15:32
Unknown error during task verification
Roman
Level 41
3 July 2019, 09:47
Do not use Thread.currentThread().interrupt(). You interrupted tests.