Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the SwingWorker task

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use SwingWorker tasks", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use SwingWorker tasks" this article.

SwingWorker task queue

RemoteTable uses a QueuedExecutor to schedule its SwingWorker tasks, and QueuedExecutor executes all tasks sequentially in a single thread. QueuedExecutor is part of DougLea's util.concurrent package, see the Resources section below. The remote model notifies its listeners with a RMI callback operation

To support visual feedback, RemoteTable sends Task events to registered Task listeners. When the task enters scheduling, the listener's taskStarted () is called and taskEnded () is called when the task is completed. The client demo uses these events to start or stop a small animation and update the status.

Execution order

Represents the update process of the cell. The event dispatch thread with the start and end of the execution process on the left. The SwingWorker task is executed in the thread of the executor on the right. The execution of the finished () method of Worker is not shown.

SwingWorker task simplification

For simplicity, the remote model does not protect conflicting editors. So only one editor can be running at a time. Concurrent editing can be achieved by adding a request ID (requestIDs). )

Another simplified decision made is that the client and server must negotiate the column structure of the table in advance. In other words, the server client provides row data, and the client must already know what table they are dealing with. The client for the demonstration uses DefaultModelTemplate to pre-define the names and classes of each column to determine which cells can be edited. (in the demo, the first two columns are not editable. )

The rest of this section describes the class structure and implementation. If you don't want to know the revised SwingWorker used in this demo, you can skip it. The downloads section explains how to download and run the demo.

SwingWorker task implementation

The remote model implements the RemoteTableModel interface, which is similar to AbstractTableModel, except that all its methods throw exceptions. To start a client, the remote table model sends a full update event to the listener that the client has registered.

RemoteTableModelAdapter connects any TableModel to a RemoteTableModel. The table model in the demo program is taken from TheJavaTutorial, but some delays are inserted to simulate the actual situation. The remote table model event contains the value of the updated cell.

The RemoteTable component uses a DefaultRemoteTableModelListener to accept callbacks from the remote model. This listener updates the local model in the event dispatch thread. Because the remote model may be notified to insert or delete certain rows, the listener requires the local model to support insert and delete operations, and DefaultTableModel meets this requirement.

The above is all the contents of the article "how to use SwingWorker tasks". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report