Could anyone please explain what's going on in this program? I don't understand what it's supposed to help us visualise. When I run the program, I don't understand why it's flagging false when results is identical to expected results (I decreased the size of the array to 50 so I could make sure that was the case).
Can't quite understand
You must be signed in to leave a comment
30 July 2020, 04:25
by decreasing size of the arraydo not forget to decrease size of expectedResult StringBuffer better change it to the length of testArray is deliberately so high to show that sometimes the results evaluates to true and sometimes to false. this is because of intentional delay in starting thread.join(). there are two loops in initThreads(): and that means that threads are unleashed one by one starting to vie one with another biting the numbers with no mercy. and only when they are halfway we say to wait one for another. but the mess has been already done. if you do it in one loop like this: then the result will always be true
1 October 2020, 18:04
but if we do so, then everything will be in sequence and the property of running the threads parllely fails. @_@ well the motive of this task is to show that only how actually the mess is created and probability of getting correct result(!true) is very less. So we will add join method to all the thread after they started running so as to make the main Thread wait until child thread has stopped finishing their work.