I did solve it,but i didn't use extra checker "if String is NOT equal to Zero"
(if (string!=null) {
result.add(s);,
and after it has passed the validator - I didn't get why do we need it?
Also i do have an issues with debugging multithreading Solutions, is anyone could suggest anything - how you could see every thread is going through the program - not just Main thread? Because default IntelijIdea debugger just not showing what is going with other Threads.
Anatoly
Level 17
How to debug it?
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
10 March 2021, 18:37useful
Put System.out.println() methods around your code to output pertinent information. Also you can very easily set a break point in the run method of the threads, that would capture the thread. If you want a specific thread then use an if statement on its name. This task doesn't use thread names so you wouldn't be able to do that here, but this is what it would look like:
then in the run method just have an if statement checking for the name and then 1 line of code to break at:
Now you would be on the specific thread that you wanted.
+1
Anatoly
10 March 2021, 20:19
Thank you very much Guadalupe! Very useful advice.
I figured out about breakpoint into Run method, but it catches just one of the all Threads, and it looks,like it really happens randomly, which is not helped a lot with understanding program flow..
Thanks for the advice with name - would try to do that..
One more question - may test more,than one Thread simultaneously,coding that way:
public void run() {
if(getName().equals("myNameForThread"))
System.out.println(); // set break point on this line
if(getName().equals("2ndNameForThread"))
System.out.println();
}
Will it catch 2 threads,or 10,or i should test each thread,catching it by name - only one thread per test?
+1
Guadalupe Gagnon
10 March 2021, 20:40useful
The debug goes line by line. Having multiple threads would get very very confusing trying to go line by line. I would instead build an output specific for you for each thead:
This is just a quick example, but you code those lines to capture whatever data that you want, formatted to whatever you think will work for you. When the thread ends just print what data was captured and all the information gathered would displayed per thread, not all mixed up. +2
Anatoly
12 March 2021, 20:56
Wow! Thanks a lot!
Saved the script - and pretty sure it'll help to understand the topic better.
Thanks again for your time!
+1