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 (14)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
26 January, 06:06
Oh! I even didn't notice it is hard... Good task.
Jonaskinny Java Developer at Sandmedia
13 April 2022, 18:46
Good one for specific requirement of action taken in a given method, as it impacts the output.
aijo
Level 30 , Germany, Germany
12 February 2022, 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.:
Michaela Obertova
Level 29 , Prievidza
28 October 2022, 08:00
It does say the following: 2.3. The thread numbers must start with 1. 5. In the end, 15 lines should be output to the console. If you initialize the createdThreadCount at 1, it will only output 14 lines to the console.
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 39 , 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.
remote87
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 2022, 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()