title: Inserting data to database is freezing my app
body: <p>I have got class with timer. This class is adding new items for my Array of points. That points are moving and from a body of timer im repainting a panel to draw them in new positions. Im connected to database sqlite. when im calling an insert function to add point to the table - apps freeze for 1s. </p>
  
  <p>I want to ask is there any way to not stoping drawing/repainting? i want that operation of inserting will be doing in background. </p>
  
  <p>any ideas?</p>
  
  <p>Ps: i heard about swing worker but idk is it suitable to my sitaution</p>
  
  <p>EDIT:</p>
  
  <pre><code>class Generator{
      ChangeListener listener;
      ArrayList&lt;String&gt; s;
      JPanel p;
      Timer generatorTimer;
      MyDatabase b;
  
  
      public Generator(){
      this.s = new ArrayList&lt;String&gt;();
      this.b = new MyDatabase();
        generatorTimer = new Timer(40, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
                addItem();     
                p.repaint();
        }
      });
      generatorTimer.start();
      }
      private void addItem(){
          String newString = new String("sampleText");
          s.add(newString);
          b.insert(newString);  //inserting new item do database
          listener.stateChanged(new ChangeEvent(this));
      }
      public void setPanel(JPanel p){
          this.p = p;
      }
  
      public ArrayList&lt;String&gt; getArray(){
          return s;
      }   
      public void addListener(ChangeListener list){
          this.listener = list;
      }
  }
  </code></pre>
  
  <p>Can u give me example how to replace my <code>Timer</code> with a <code>SwingWorker</code>?</p>