
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class Threadsicher extends JFrame {

  public Threadsicher() {
    final DefaultListModel model = new DefaultListModel();
    JList list = new JList( model );

    setSize( 300, 200 );
    this.getContentPane().add( list );

    new Thread(){ public void run() {
        setPriority( Thread.MIN_PRIORITY );
        while ( true )
          model.addElement( "Dumm gelaufen" );
      }
    }.start();

    new Thread(){ public void run() {
        //setPriority( Thread.MIN_PRIORITY );
        while ( true )
          model.removeElement( "Dumm gelaufen" );
      }
    }.start();
  }




  //Überschreiben, damit das Programm bei Herunterfahren des Systems beendet werden kann
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }


  public static void main(String[] args) {
    Threadsicher frame = new Threadsicher();
    frame.setVisible(true);
  }


}


