1 UI application
The user is boss of the application, so the UI thread has highest priority. workerthread has lower priority.
· Keep the priorityof worker threads low.
· Keep the numberof worker threads small.
· Consider suspending worker threads duringCPU-intensive operations like scrolling.
Key Points
- Using threads is essential for building responsive GUIs. Blocking user activity to wait for long tasks to complete leads to poor perceived performance.
- The user is the boss. Always let your users know what's going on and give them regular status updates when waiting for long tasks to complete.
- Once realized, Swing components should only be touched by code executing inside the AWT event-dispatch thread.
- Use invokeLater and invokeAndWait to move work to the event dispatching thread.
- Use timers for repeated operations. You can use either the javax.swing.Timer or java.util.Timer. The utility Timer class gives you more control, but you have to move work to the event- dispatch thread yourself. You can use the SwingTimerTask utility described in this chapter to move work to the event-dispatch thread.
- Use SwingWorker to execute time-consuming tasks on new threads and update the GUI on the event-dispatch thread.
- Interrupt worker threads when the user is driving the system.
2 Real time server application:

本文讨论了UI线程与工作线程在应用程序中的重要性,强调了使用线程对于构建响应迅速的GUI至关重要。文章介绍了如何通过合理设置工作线程的优先级、数量及适时挂起等手段来提高用户体验,并提供了Swing组件的最佳实践,如利用invokeLater与invokeAndWait方法将任务转移至事件分发线程。
1307

被折叠的 条评论
为什么被折叠?



