Skip to content

Commit

Permalink
Hide ThreadFactory interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 7, 2012
1 parent 9fb5d63 commit 12ec5f0
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/main/java/com/github/sarxos/webcam/WebcamMotionDetector.java
Expand Up @@ -20,10 +20,26 @@
*
* @author Bartosz Firyn (SarXos)
*/
public class WebcamMotionDetector implements ThreadFactory {
public class WebcamMotionDetector {

private static final Logger LOG = LoggerFactory.getLogger(WebcamMotionDetector.class);

/**
* Create new threads for detector internals.
*
* @author Bartosz Firyn (SarXos)
*/
private class DetectorThreadFactory implements ThreadFactory {

@Override
public Thread newThread(Runnable runnable) {
Thread t = new Thread(runnable, "motion-detector-" + (number++));
t.setDaemon(true);
return t;
}

}

/**
* Run motion detector.
*
Expand Down Expand Up @@ -123,10 +139,15 @@ public void run() {
*/
private int number = 0;

/**
* Thread factory.
*/
private ThreadFactory threadFactory = new DetectorThreadFactory();

/**
* Executor.
*/
private ExecutorService executor = Executors.newCachedThreadPool(this);
private ExecutorService executor = Executors.newCachedThreadPool(threadFactory);

/**
* Create motion detector. Will open webcam if it is closed.
Expand Down Expand Up @@ -303,11 +324,4 @@ public boolean isMotion() {
public int getMotionStrength() {
return strength;
}

@Override
public Thread newThread(Runnable runnable) {
Thread t = new Thread(runnable, "motion-detector-" + (number++));
t.setDaemon(true);
return t;
}
}

0 comments on commit 12ec5f0

Please sign in to comment.