Java swing – running on EDT

I have a few questions about swing and use EDT to update the GUI I've just started reading this, so I'm a new beginner in this field:

>What operations are running on EDT? If not, just raise an objection? > Is there a specific time when we are actually in EDT automatically? > If we use singutilities Invoke scheduling task, we queue it to the current GUI update task queue? > I guess accessing the above queue is synchronous or using some concurrent collections, but if I schedule two GUI update tasks from two background threads, can't I say one first? For example, if thread 1 first submits a task with jlable text set to "yes", and then after a short time, the second thread will appear and submit a task with this value set to "no", do we guarantee that the result will be "yes", or is it just a problem for the operating system to arrange these things? > How does swingworker really run the done () method on EDT? It sets the following code:

future = new FutureTask<T>(callable) {
               @Override
               protected void done() {
                   doneEDT();
                   setState(StateValue.DONE);
               }
           };

So I wonder if futuretask ensures that invoker is called in some way?

Thank you for all your answers

Solution

>A good rule is that all operations (access / update /...) should occur on EDT Some exceptions are mentioned in Javadoc (some methods of some classes), but it is difficult to remember that it is easier to adhere to the "do everything on EDT" method Exceptions are not raised (fortunately, JavaFX solves this shortcoming) You can use a custom repaintmanager to detect most of these violations: see this article

private void doneEDT() {
    Runnable doDone = 
        new Runnable() {
            public void run() {
                done();
            }
        };
    if (SwingUtilities.isEventDispatchThread()) {
        doDone.run();
    } else {
        doSubmit.add(doDone);
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>