Changeset 31590

Show
Ignore:
Timestamp:
07.04.2017 11:00:30 (2 years ago)
Author:
ak19
Message:

Better synchronization I think. I've declared methods as synchronized, to make sure that the EventListeners? are synchronized on too, rather than synchronizing only on the BufferedWriter? object.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/GS2PerlConstructor.java

    r31578 r31590  
    658658    // exceptions when reading from our perl process' stderr and stdout streams are handled by 
    659659    // SynchronizedProcessLineByLineHandler.gotException() below. 
    660     public void gotException(Exception e) { 
     660    public synchronized void gotException(Exception e) { 
    661661 
    662662    // do what original runPerlCommand() code always did when an exception occurred 
     
    688688    } 
    689689 
    690     public void gotLine(String line) { 
     690    public synchronized void gotLine(String line) { 
    691691        //if(this.source == STDERR) { 
    692692        ///System.err.println("ERROR: " + line); 
     
    701701        // "All methods on Logger are multi-thread safe", see 
    702702        // http://stackoverflow.com/questions/14211629/java-util-logger-write-synchronization 
    703  
    704         try { 
    705         synchronized(bwHandle) { // get a lock on the writer handle, then write 
     703         
     704        try {        
     705        bwHandle.write(line + "\n"); 
    706706         
    707             bwHandle.write(line + "\n"); 
    708         }  
    709707        } catch(IOException ioe) { 
    710708        String msg = (source == STDERR) ? "stderr" : "stdout"; 
     
    716714        // and only immutable (final) vars are used. 
    717715        sendProcessStatus(new ConstructionEvent(GS2PerlConstructor.this, GSStatus.CONTINUING, line)); 
    718     }    
     716    } 
    719717 
    720718    // This is called when we get an exception during the processing of a perl's 
    721719    // input-, err- or output stream 
    722     public void gotException(Exception e) { 
     720    public synchronized void gotException(Exception e) { 
    723721        String msg = (source == STDERR) ? "stderr" : "stdout"; 
    724722        msg = "Got exception when processing the perl process' " + msg + " stream.";