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/
    世界丰富多彩,知识天花乱坠。
    ---如果有帮到你,点个赞吧~
  • 相关阅读:
    MYSQL学习笔记
    javascript30--day01--Drum kit
    jQuery--dataTable 前端分页与后端分页 及遇到的问题
    hexo博客
    js—数组那些事儿
    累死青蛙系列——青蛙跳台阶问题
    js—求数组中的最大最小值
    前端html,css考点
    doxygen 使用 教程 不含安装仅设置
    fatal error LNK1169: one or more multiply defined symbols found 终极解决方案
  • 原文地址:https://www.cnblogs.com/java2sap/p/15132791.html
Copyright © 2011-2022 走看看