com.github.sarxos.webcam.WebcamShutdownHook Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webcam-capture Show documentation
Show all versions of webcam-capture Show documentation
This library allows you to use your PC webcam, IP or network cameras directly from Java. It's compatible with most operating systems (Windows, Linux, MacOS).
The newest version!
package com.github.sarxos.webcam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Shutdown hook to be executed when JVM exits gracefully. This class intention
* is to be used internally only.
*
* @author Bartosz Firyn (sarxos)
*/
public final class WebcamShutdownHook extends Thread {
/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(WebcamShutdownHook.class);
/**
* Number of shutdown hook instance.
*/
private static int number = 0;
/**
* Webcam instance to be disposed / closed.
*/
private Webcam webcam = null;
/**
* Create new shutdown hook instance.
*
* @param webcam the webcam for which hook is intended
*/
protected WebcamShutdownHook(Webcam webcam) {
super("shutdown-hook-" + (++number));
this.webcam = webcam;
this.setUncaughtExceptionHandler(WebcamExceptionHandler.getInstance());
}
@Override
public void run() {
LOG.info("Automatic {} deallocation", webcam.getName());
webcam.dispose();
}
}