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
Creating threads recursively
- 18
Locked
Comments (14)
- Popular
- New
- Old
You must be signed in to leave a comment
Олег БайбулаExpert
26 January, 06:06
Oh! I even didn't notice it is hard... Good task.
0
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.
0
aijo
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.:
0
Michaela Obertova
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.
0
Tamas Horcsak
10 December 2021, 21:13
my code generated only one line and passed 😬😬
0
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...
0
Justin Smith
10 September 2021, 21:20
I liked this one. Recursion is fun.
0
Jurij Thmsn
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.
0
remote87
4 March 2021, 21:39
4 attempts...changed something...did not see what...but it passed :D
0
Lex Icon
27 February 2021, 12:22
Daaamn it...46 attempts before I realized what's the point of the entire program.
0
Oliver Heintz
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.
0
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()
0