Hijacking threads x years old ain’t recommended. Instead of implementing your own polling simply use the sonar.qualitygate.wait property, see
sonar.qualitygate.wai