@Override
    public void run() {
        // The file pointer keeps track of where we are in the file
        long filePointer = 0;
        long startTime = new Date().getTime();
        
        // Determine start point
        if (this.startAtBeginning) {
            filePointer = 0;
        } else {
            filePointer = this.file.length();
        }
        
        try {
            // Start tailing
            this.tailing = true;
            RandomAccessFile file = new RandomAccessFile(this.file, "r");
            while (isTailing()) {
                //check to see if maxActiveInterval has been exceeded
                if (new Date().getTime() - startTime > this.maxActiveInterval) {
                    if (log.isWarnEnabled()) {
                        log.warn("FileTailer exceeded maxActiveInterval: " + this.maxActiveInterval);
                    }
                    stopTailing();
                    fireMaxActiveIntervalExceeded();
                }
                try {
                    // Compare the length of the file to the file pointer
                    long fileLength = this.file.length();
                    if (fileLength < filePointer) {
                        // file must have been rotated or deleted;
                        // reopen the file and reset the file pointer
                        file = new RandomAccessFile(this.file, "r");
                        filePointer = 0;
                    }
                    
                    if (fileLength > filePointer) {
                        // There is data to read
                        file.seek(filePointer);
                        String line = file.readLine();
                        while (line != null) {
                            fireNewFileLine(line);
                            line = file.readLine();
                        }
                        filePointer = file.getFilePointer();
                    }
                    
                    // Sleep for the specified interval
                    Thread.sleep(this.interval);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
            
            // Close the file that we are tailing
            file.close();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
@ Override public void run ( ) { long filePointer = 0 ; long startTime = new Date ( ) . getTime ( ) ; if ( this . startAtBeginning ) { filePointer = 0 ; } else { filePointer = this . file . length ( ) ; } try { this . tailing = true ; RandomAccessFile file = new RandomAccessFile ( this . file , "r" ) ; while ( isTailing ( ) ) { if ( new Date ( ) . getTime ( ) - startTime > this . maxActiveInterval ) { if ( log . isWarnEnabled ( ) ) { log . warn ( "FileTailer exceeded maxActiveInterval: " + this . maxActiveInterval ) ; } stopTailing ( ) ; fireMaxActiveIntervalExceeded ( ) ; } try { long fileLength = this . file . length ( ) ; if ( fileLength < filePointer ) { file = new RandomAccessFile ( this . file , "r" ) ; filePointer = 0 ; } if ( fileLength > filePointer ) { file . seek ( filePointer ) ; String line = file . readLine ( ) ; while ( line != null ) { fireNewFileLine ( line ) ; line = file . readLine ( ) ; } filePointer = file . getFilePointer ( ) ; } Thread . sleep ( this . interval ) ; } catch ( Exception e ) { log . error ( e . getMessage ( ) , e ) ; } } file . close ( ) ; } catch ( Exception e ) { log . error ( e . getMessage ( ) , e ) ; } }
Typically executed via a <code>new Thread(FileTailer).start()</code>