And*_*Hin 5 java swing multithreading timer
我正在使用javax.swing.Timer来安排和运行事件.但它似乎冻结了GUI.只是想知道这些事件是在单独的线程上运行还是我必须自己完成.
谢谢
"Although all Timers perform their waiting using a single, shared thread (created by the first Timer object that executes), the action event handlers for Timers execute on another thread -- the event-dispatching thread. This means that the action handlers for Timers can safely perform operations on Swing components. However, it also means that the handlers must execute quickly to keep the GUI responsive."—javax.swing.Timer
Emphasis added.
附录:SwingWorker专为这种情况而设计.特别是,它提供了一种方便的方式来卸载工作,同时定期在EDT上重建进度.