Do not use this
System.currentTimeMillis()-startTime
It may cause hang on host machine time change.
Better use this way:
Integer i = 0;
try {
while (condition && i++ < 100) {
Thread.sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
(100*100 = 10 sec timeout)