zoukankan      html  css  js  c++  java
  • SwingWorker.publish 方法注释写的很清楚, 尤其是标红处

    void javax.swing.SwingWorker.publish(V... chunks)

    Sends data chunks to the process method. This method is to be used from inside the doInBackground method to deliver intermediate results for processing on the Event Dispatch Thread inside the process method.

    Because the process method is invoked asynchronously on the Event Dispatch Thread multiple invocations to the publish method might occur before the process method is executed. For performance purposes all these invocations are coalesced into one invocation with concatenated arguments.

    For example:

     publish("1");
     publish("2", "3");
     publish("4", "5", "6");
     

    might result in:

     process("1", "2", "3", "4", "5", "6")
     

    Sample Usage. This code snippet loads some tabular data and updates DefaultTableModel with it. Note that it safe to mutate the tableModel from inside the process method because it is invoked on the Event Dispatch Thread.

     class TableSwingWorker extends 
             SwingWorker<DefaultTableModel, Object[]> {
         private final DefaultTableModel tableModel;
     
         public TableSwingWorker(DefaultTableModel tableModel) {
             this.tableModel = tableModel;
         }
     
         @Override
         protected DefaultTableModel doInBackground() throws Exception {
             for (Object[] row = loadData(); 
                      ! isCancelled() && row != null; 
                      row = loadData()) {
                 publish((Object[]) row);
             }
             return tableModel;
         }
     
         @Override
         protected void process(List<Object[]> chunks) {
             for (Object[] row : chunks) {
                 tableModel.addRow(row);
             }
         }
     }
     
    Parameters:
    chunks intermediate results to process
    See Also:
    process
    博客地址: https://www.cnblogs.com/java2sap/
    世界丰富多彩,知识天花乱坠。
    ---如果有帮到你,点个赞吧~
  • 相关阅读:
    Android学习总结——实现Home键功能
    Android学习总结——SQLite
    Android学习总结——文件储存
    Android学习总结——SharedPreferences
    Android学习总结——Content Provider
    Android学习总结——Service组件
    IDEA 创建和使用tomcat
    IDEA 图标介绍。 缓存和索引介绍、清理方法和Debug使用
    IDEA 常用快捷键
    IntelliJ IDEA常用设置(一)
  • 原文地址:https://www.cnblogs.com/java2sap/p/15132791.html
Copyright © 2011-2022 走看看