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();
System.out.println(startTime);
for (int count = 0; ;count++) {
long now = System.currentTimeMillis();
if(now – startTime >= 10000) break;
// Do nothing
}
System.out.println(System.currentTimeMillis());

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

Leave a Reply

Your email address will not be published.

WP2Social Auto Publish Powered By : XYZScripts.com