title: Dynamically loading large data in jTable using SwingWorker
body: <p>In Netbeans, I am trying to create a Desktop Application whose UI looks like below:</p>
  
  <p><a href="https://i.stack.imgur.com/3b0vP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3b0vP.png" alt="enter image description here"></a></p>
  
  <p>I am executing "adb logcat command" through Java code which loads 1000s of lines of logs in few seconds &amp; I intend to display all of this information through jTable in NetBeans. </p>
  
  <p>Using parameter: adb logcat -t 100 -> I am restricting the logs to 100 lines only right now.
  However the applet becomes unresponsive (or gets stuck in process() method) for 1000 lines or when removing such restriction on number of lines.</p>
  
  <p>I am not sure whether I have properly implemented the SwingWorker thread in my code. I am looking for suggestions on how to improve the code for loading large amount of data dynamically without applet becoming unresponsive.</p>
  
  <p>Following is the implemented code for the applet... with 2 functions:</p>
  
  <ol>
  <li>viewLogs() called from init() method of applet.</li>
  <li><p>SwingWorker implementation.</p>
  
  <pre><code>    public void viewLogs() throws IOException {
  
      String[] command = {"CMD","/C", "adb logcat -t 100"};
      ProcessBuilder probuilder = new ProcessBuilder( command );
      probuilder.directory(new File("c:\\Users\\k.garg\\Desktop\\"));
      Process process = probuilder.start();
  
      InputStream is = process.getInputStream();      
      InputStreamReader isr = new InputStreamReader(is);
      br = new BufferedReader(isr);
  
      DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
      worker.execute();
  
      try {
          int exitVal = process.waitFor();
          System.out.println("exitVal = " + exitVal);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  }
  public class TableSwingWorker extends SwingWorker&lt;DefaultTableModel, Object[]&gt;{
  private DefaultTableModel tableModel;
  public TableSwingWorker(DefaultTableModel tableModel){
      this.tableModel = tableModel;
  }
  
  @Override
  protected DefaultTableModel doInBackground() throws Exception {
      Thread.sleep(2000); //added for initial UI to load
      System.out.println("Start populating");
      String line, date, time, loglevel, PID, TID, tag, message="";
      String log;
      int count = 0;
      while ((log = br.readLine()) != null) {
          count++;
  
          String[] splitLog = log.trim().split("\\s+");
          line = Integer.toString(count);
          date = splitLog[0];
          time = splitLog[1];
          PID = splitLog[2];
          TID = splitLog[3];
          loglevel = splitLog[4];
          tag = splitLog[5];
          for(int i=6; i&lt;splitLog.length;i++){
              message += splitLog[i];
          }
          publish(new Object[]{line, date, time, PID, TID, loglevel, tag, message});
      }
      return tableModel;
  }
  
  @Override
  protected void process(List&lt;Object[]&gt; chunks) {
      System.out.println("Adding " + chunks.size() + " rows");
      for(Object[] row: chunks)
          tableModel.insertRow(0,row);
  }
  </code></pre>
  
  <p>}</p></li>
  </ol>