Thread.Sleep() is freezing

后端 未结 3 683
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 08:30

Here is a snippet

kit.insertHTML(doc, doc.getLength(), \"Hello\", 0, 0, null);
try{
Thread.sleep(1000);
}catch(Exception e){}

I am using

3条回答
  •  一整个雨季
    2020-11-27 09:28

    You are calling sleep on the EDT (Event Dispatching Thread). You should avoid this situation as indeed, it freezes the UI.

    To avoid this situation, use a SwingWorker instead or as suggested by HFOE, use a Swing Timer

提交回复
热议问题