Creating threads recursively

  • 18
  • Locked
1. Change the GenerateThread class to make it a thread. 2. Create a GenerateThread constructor, which must: 2.1. Call the superclass's constructor, passing the created thread's number as a String. Use createdThreadCount. 2.2. Start the current thread. 2.3. The thread numbers must start with 1. 3. O
You can't complete this task, because you're not signed in.
Comments (12)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Jonaskinny Java Developer at Sandmedia
13 April, 18:46
Good one for specific requirement of action taken in a given method, as it impacts the output.
Level 30 , Germany, Germany
12 February, 09:47
"2.3. The thread numbers must start with 1." I simply initialised createdThreadCount at 1, but this solution isn't accepted. The condition below is only in requirements, not conditions, so beware ;) "The GenerateThread class constructor should increment createdThreadCount and pass it as a string to the superclass constructor.:
Tamas Horcsak
Level 18 , Leeds, United Kingdom
10 December 2021, 21:13
my code generated only one line and passed 😬😬
Karas Java Developer
16 September 2021, 00:05
Definitelly worth those 18 pices of Dark Matter. Simplification does it some pointers: remember using super() to send to parent class. Use String.valueOf to change int to String toString is just another methoth of GenerateThread If else statement in the run and voaila Completelly DRY Recursion... wait... that is paradoxical...
Justin Smith
Level 29 , Greenfield, USA, United States
10 September 2021, 21:20
I liked this one. Recursion is fun.
Jurij Thmsn
Level 29 , Flensburg, Germany
22 March 2021, 14:45
really tough exercise, just solved it by trying and sneaking in the help section. I wish, there would be an explanation of the code afterwards. pure confusion.
Level 18 , Sofia, Bulgaria
4 March 2021, 21:39
4 attempts...changed something...did not see what...but it passed :D
Lex Icon
Level 17 , Sofia, Bulgaria
27 February 2021, 12:22
Daaamn it...46 attempts before I realized what's the point of the entire program.
Oliver Heintz
Level 18 , Mustang, United States
8 February 2021, 15:56
I guess I just don't understand how start() and run() work. I'm getting held up because it seems like if your run method creates a new GenerateThread, and GenerateThread increments createdThreadCount, that createdThreadCount would increase. I can't seem to get it to work that way.
Jonaskinny Java Developer at Sandmedia
13 April, 18:37
If you subclass Thread, and call start() on that Thread, that in turn calls that thread's run(). If you implemented Runnable Interface and call start() on the instance of that Runnable, it calls that Runnable's run(). So in this case its subclassing, so run() gives you a space, like a callback method, to put your stuff into an otherwise managed instance (Thread) where once you call start() Eventually it calls run() and fires your stuff. Since you are using recursion in this case, it comes down to how you increment the shared variable used in the comparison. create GenerateThread which checks to see if it should create a GenerateThread and then if it did so it should then output that Thread's toString()
Level 23 , Columbia, United States
14 August 2020, 01:18
Deceptively easy. Using a while loop with nested if statement messed up the answer even though output was the same (just different order). An if statement in the run() method was accepted.