Delay without using Thread.sleep() in java

While i was developing Java Swing based application I had a situation to delay my Event Dispatcher thread (EDT) for about 10 seconds. When I used standard Thread.sleep() my entire UI went for a sleep (or not responding). After lots of googling I figured out that if we call Thread.sleep()  in EDT it will put the GUI into sleep as well. I later wrote following lines of code to achieve 10 seconds delay as a function,

long startTime = System.currentTimeMillis();
for (int count = 0; ;count++) {
long now = System.currentTimeMillis();
if(now – startTime >= 10000) break;
// Do nothing

It worked for me and I hope it will help some one.

WP2Social Auto Publish Powered By :