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/
    世界丰富多彩,知识天花乱坠。
    ---如果有帮到你,点个赞吧~
  • 相关阅读:
    奇怪吸引子---Bouali
    奇怪吸引子---Arneodo
    奇怪吸引子---AnishchenkoAstakhov
    奇怪吸引子---Aizawa
    混沌图像---三翅鹰
    混沌图像---马丁迭代【密集恐惧症患者慎入】
    混沌图像---埃农的猫头鹰
    MySQL存储过程 事务transaction
    OBS直播抖音。。。
    [译][python]ImportError:attempted relative import with no known parent package
  • 原文地址:https://www.cnblogs.com/java2sap/p/15132791.html
Copyright © 2011-2022 走看看