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.
Merge pull request #665 from tinwelint/fix-flappy-get-or-create-test

Fixes a rare test timing issue