Skip to content

Commit

Permalink
Merge pull request #181 from pdowler/master
Browse files Browse the repository at this point in the history
MultiBufferIO: set thread name for writer thread
  • Loading branch information
pdowler authored Jan 25, 2022
2 parents 899b6fd + 92f07cc commit 0d20f60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cadc-util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.5.9'
version = '1.5.10'

description = 'OpenCADC core utility library'
def git_url = 'https://github.com/opencadc/core'
Expand Down
47 changes: 30 additions & 17 deletions cadc-util/src/main/java/ca/nrc/cadc/io/MultiBufferIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@

package ca.nrc.cadc.io;

import ca.nrc.cadc.thread.ConditionVar;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.BlockingQueue;
Expand Down Expand Up @@ -131,22 +130,36 @@ public void copy(InputStream input, OutputStream output) throws InterruptedExcep
}

Worker w = new Worker(output);
Thread writer = new Thread(w);
writer.start();

Throwable readFail = doit(input, w);
log.debug("reader completed: " + readFail);
if (readFail != null) {
writer.interrupt();
}
writer.join();
log.debug("writer completed: " + w.fail);

if (readFail != null) {
throw new ReadException(READ_FAIL, readFail);
}
if (w.fail != null) {
throw new WriteException(WRITE_FAIL, w.fail);
Thread writer = new Thread(w, MultiBufferIO.class.getSimpleName() + "-writer");
try {
writer.start();

Throwable readFail = doit(input, w);
log.debug("reader completed: " + readFail);
if (readFail != null) {
writer.interrupt();
}
writer.join();
log.debug("writer completed: " + w.fail);

if (readFail != null) {
throw new ReadException(READ_FAIL, readFail);
}
if (w.fail != null) {
throw new WriteException(WRITE_FAIL, w.fail);
}
} finally {
if (writer.isAlive()) {
try {
log.error("BUG: " + writer.getName() + " still alive in finally - interrupting...");
writer.interrupt();
log.error("BUG: " + writer.getName() + " interrupted in finally - waiting...");
writer.join();
log.error("BUG: " + writer.getName() + " still alive in finally - finished");
} catch (Exception ex) {
log.error("OOPS: failed to kill " + writer.getName(), ex);
}
}
}
}

Expand Down

0 comments on commit 0d20f60

Please sign in to comment.