Java Swingworker Thread

廉价感情. 提交于 2019-12-11 13:16:20

问题


I have a question to ask about Java Concurrency. I'm practicing Java Threading. What i do is create a simple interface which has a button and a JSlider. So when i click the button a variable will increase and the JSlider moving accordingly. Now I wonder if Swingworker is a right choice.


回答1:


You only need to use SwingWorker for long-running tasks. What you describe will be performed instantly. Therefore you can do this on the Event Dispatch Thread, where all ActionListeners are performed.




回答2:


You may want to profile your code first.

  • Examples where a state change does not block the EDT: here and here.

  • An example where an action might block the EDT: here.

  • An example where an action will block the EDT: here.



来源:https://stackoverflow.com/questions/12319484/java-swingworker-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!