Skip to content

Commit

Permalink
Illegal state exception when adding shutdown hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Dec 27, 2014
1 parent 1a7198a commit f2a5d33
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ public boolean open(boolean async) {

LOG.debug("Webcam is now open {}", getName());

// install shutdown hook

try {
Runtime.getRuntime().addShutdownHook(hook = new WebcamShutdownHook(this));
} catch (IllegalStateException e) {

LOG.debug("Shutdown in progress, do not open device");
LOG.trace(e.getMessage(), e);

close();

return false;
}

// setup non-blocking configuration

if (asynchronous = async) {
Expand All @@ -292,10 +306,6 @@ public boolean open(boolean async) {
updater.start();
}

// install shutdown hook

Runtime.getRuntime().addShutdownHook(hook = new WebcamShutdownHook(this));

// notify listeners

WebcamEvent we = new WebcamEvent(WebcamEventType.OPEN, this);
Expand Down

0 comments on commit f2a5d33

Please sign in to comment.