看个例子吧:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.border.*;public class SpyLogFrame extends JFrame {
  //这个面板将包括编辑器的主面板
  JPanel contentPane;
  //菜单+工具条+编辑区+状态条的布局对象
  BorderLayout borderLayout1 = new BorderLayout();  //菜单条=====================================
  JMenuBar menuBar1 = new JMenuBar();
  //文件菜单
  JMenu menuFile = new JMenu();
  JMenuItem menuFileExit = new JMenuItem();
  //帮助菜单
  JMenu menuHelp = new JMenu();
  JMenuItem menuHelpAbout = new JMenuItem();
  //动态定义的菜单对象
  JMenuItem jMenuItem1 = new JMenuItem();
  JMenuItem jMenuItem2 = new JMenuItem();
  JMenuItem jMenuItem3 = new JMenuItem();
  JMenuItem jMenuItem4 = new JMenuItem();
  JMenu jMenu1 = new JMenu();
  JMenuItem jMenuItem6 = new JMenuItem();
  JMenuItem jMenuItem7 = new JMenuItem();
  //工具条======================================
  JToolBar toolBar = new JToolBar();
  JToolBar toolBarSlider = new JToolBar();  //按纽
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  //按纽图标
  ImageIcon image1;
  ImageIcon image2;
  ImageIcon image3;
  ImageIcon image4;
  ImageIcon image5;
  ImageIcon image6;  //文本编辑区============================================
  //带滚动条的面板
  JScrollPane jScrollPane1 = new JScrollPane();
  //文本框
  JTextArea jTextArea1 = new JTextArea();  //状态条==========================================
  JLabel statusBar = new JLabel();  //文件打开对话框对象
  JFileChooser jFileChooser1 = new JFileChooser();
  public  static String currFileName = null;  // Full path with filename. null means new/untitled.  //是否脏读
  public  static boolean dirty = true;
   //监视频率(毫秒)
  public static int  SPY_MILLIS  =100 ;
  //监视线程
  java.lang.Thread spy_thread =new java.lang.Thread(new SpyThread( jTextArea1),"Spy_log0");  Document document1;
  TitledBorder titledBorder1;
  JSlider jSlider1 = new JSlider();
  JLabel jtitle=new JLabel("监视频率:");  //构造函数
  public SpyLogFrame(String currFileName) {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    //System.out.println(AWTEvent.WINDOW_EVENT_MASK);
    this.currFileName=currFileName;
    try {
      //初始化窗体布局
      jbInit();
      //更新窗口标题
      updateCaption();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

解决方案 »

  1.   

    /*
    监视log文件变化线程
    */
    class SpyThread extends java.lang.Thread{        public JTextArea jTextArea1=null;
            public SpyThread(JTextArea jt){
                    jTextArea1=jt;
            }
            //是否监视文件
            public static boolean spy_Loop = true; //监视频率(毫秒)
    public final static int  SPY_MILLIS  =1000 ; public void run(){
    while (spy_Loop){
    //System.out.println(java.lang.Thread.currentThread()+Long.toString(System.currentTimeMillis()));
    try{
    java.lang.Thread.currentThread().sleep(SPY_MILLIS);
                                     spyLog();
    }catch(InterruptedException e){} }
    }
            public   void  spyLog(){
                    String s=jTextArea1.getText();
                   int chars_read =0;
                   int size2 = 0;
                    try{
                            //根据文件名建立一个文件对象
                            File file = new File(SpyLogFrame.currFileName);
                          int size = (int)file.length();
                                   //System.out.println(">>"+size);                        //文件长度有变化
                            if(s.length() !=size){
                                    //如果是文件长度增加,只动态改变增加部分
                                    if(s.length()<size){
                                            //原始长度
                                           chars_read =s.length();
                                          //增加长度
                                          size2=size-s.length() ;
                                    }
                                    //否则如果是尺寸减少了,则重新刷新
                                    else if(s.length()>=size){
                                           chars_read =0;
                                          size2=size;
                                          s="";
                                    }
                            }
                            if(size2>0||size==0){
                                    //根据file对象建立一个input reader来读取数据
                                    FileReader in = new FileReader(file);
                                    //创建一个字符数组存放文件内容
                                    char[] data = new char[size];
                                    //从缓存中读取数据
                                    in.read(data, 0, size);                                in.close();                                //数据内容给编辑器
                                    s=s+(new String(data, chars_read, size2));                                jTextArea1.setText(s);
                                    JComponent j=jTextArea1;
                                    j.setAutoscrolls(true);
                            }
                    }
                    catch (IOException e) { }
            }/**
     * 停止监视
     */
            public   void stopSpy(){
                    spy_Loop=false;
            }/**
     * 启动监视
     */
            public   void StartSpy(){
                    spy_Loop=true;
                    run();
            }}
      

  2.   

    好象在linux下只要写个shell script就行了,也可用nohup ...来做