No interrupt, no dice?

  • 9
  • Locked
Figure out how the program works. Make it so that the ourInterrupt method allows the TestThread to terminate itself. Don't use the interrupt method.
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
Jonaskinny Java Developer at Sandmedia
11 March 2022, 17:30
I think the rationale for statics here is to kill all TestThreads, since using TestThreads this way would do exactly that. The task does highlight how hard it is to get a reference to the Runnable when we disconnect our calls from the reference t.
Justin Smith
Level 39 , Greenfield, USA, United States
6 September 2021, 16:47
I did this slightly different from the solution and it validated. Instead, the variable I used for the while loop was a static variable of TestThread. I feel this is slightly better practice because it clarifies that the variable is for the TestThread class. You might have other classes that inherit Thread that you also want to be able to end specific ones this way, for example, and if each of them have their own static variable it becomes much more clear.
Jonaskinny Java Developer at Sandmedia
11 March 2022, 17:33
that is the solution actually, perhaps they have changed it since?
remote87
Level 18 , Sofia, Bulgaria
4 March 2021, 15:23
I'm so proud of myself... so much often I see that my solution is almost the same as CodeGym's one :)
Oleksii Chernysh
Level 27 , Dnipro, Ukraine
23 November 2019, 04:52
Validation logic is not good. If a flag is not public and used via method like cancel() then validation fails. Waste of time :(