Java Swingworker 线程 [英] Java Swingworker Thread
问题描述
我有一个关于 Java 并发的问题要问.我正在练习 Java 线程.我所做的是创建一个简单的界面,它有一个按钮和一个 JSlider.所以当我点击按钮时,一个变量会增加并且 JSlider 会相应地移动.现在我想知道 Swingworker 是否是一个正确的选择.
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.
推荐答案
您只需将 SwingWorker 用于长时间运行的任务.您描述的内容将立即执行.因此,您可以在执行所有 ActionListener 的事件调度线程上执行此操作.
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.
这篇关于Java Swingworker 线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!