I'd implements Runnable
than extends Thread
implements Runnable
than extends Thread
and change the following loop
- Unfortunately, the code is still not thread safe. Although accessing array elements on separate threads could be safe accessing array elements on separate threads could be safe but the code in the question accesses the same array index from separate threads which should be synchronized properly.
This is duplicated in the code. You should move this logic into a separate method and use that to keep it DRY. Additionally, I guess the format of Arrays.toString
won't change but it would be cleaner iterating through the array and building the string with a loop or using an already existing join implementation building the string with a loop or using an already existing join implementation.
I'd implements Runnable
than extends Thread
and change the following loop
- Unfortunately, the code is still not thread safe. Although accessing array elements on separate threads could be safe but the code in the question accesses the same array index from separate threads which should be synchronized properly.
This is duplicated in the code. You should move this logic into a separate method and use that to keep it DRY. Additionally, I guess the format of Arrays.toString
won't change but it would be cleaner iterating through the array and building the string with a loop or using an already existing join implementation.
I'd implements Runnable
than extends Thread
and change the following loop
- Unfortunately, the code is still not thread safe. Although accessing array elements on separate threads could be safe but the code in the question accesses the same array index from separate threads which should be synchronized properly.
This is duplicated in the code. You should move this logic into a separate method and use that to keep it DRY. Additionally, I guess the format of Arrays.toString
won't change but it would be cleaner iterating through the array and building the string with a loop or using an already existing join implementation.
Error messages shouldn't blame the user (don't say what he did is wrong), give a suggestion about what they should do. (See: Should we avoid negative words when writing error messages? Should we avoid negative words when writing error messages?, What will be the Best notifications and error messages? What will be the Best notifications and error messages?)
Error messages shouldn't blame the user (don't say what he did is wrong), give a suggestion about what they should do. (See: Should we avoid negative words when writing error messages?, What will be the Best notifications and error messages?)
Error messages shouldn't blame the user (don't say what he did is wrong), give a suggestion about what they should do. (See: Should we avoid negative words when writing error messages?, What will be the Best notifications and error messages?)