Avoid race conditions in loadClass