Fixes a rare test timing issue

Multiple threads tried modifying the same unsynchronized ArrayList. This
created a race condition seen on certain machines/OSes in rare occasions.
Refactored to have an internal class for the thread, each instance having
a volatile field with the result instead.