Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applet - No clean shutdown, force wait 3 seconds to use #65

Closed
dmarzo opened this issue Mar 15, 2013 · 12 comments
Closed

Applet - No clean shutdown, force wait 3 seconds to use #65

dmarzo opened this issue Mar 15, 2013 · 12 comments
Assignees
Labels

Comments

@dmarzo
Copy link

dmarzo commented Mar 15, 2013

I use example webcam-capture-applet and when move to other page (applet destroy), java console show an exception, and if try to use applet in same navigator, before jvm close (2,3 seconds) no camera found.

Exception in thread "QuickCam for Notebooks Deluxe 0-repainter" com.github.sarxos.webcam.WebcamException: Offer interrupted
    at com.github.sarxos.webcam.ds.buildin.WebcamGrabberProcessor.process(WebcamGrabberProcessor.java:153)
    at com.github.sarxos.webcam.ds.buildin.WebcamGrabberTask.process(WebcamGrabberTask.java:24)
    at com.github.sarxos.webcam.ds.buildin.cgt.NextFrameTask.nextFrame(NextFrameTask.java:16)
    at com.github.sarxos.webcam.ds.buildin.WebcamDefaultDevice.getImage(WebcamDefaultDevice.java:148)
    at com.github.sarxos.webcam.Webcam.getImage(Webcam.java:308)
    at com.github.sarxos.webcam.WebcamPanel$Repainter.run(WebcamPanel.java:161)
Caused by: java.lang.InterruptedException
    at java.util.concurrent.SynchronousQueue.offer(Unknown Source)
    at com.github.sarxos.webcam.ds.buildin.WebcamGrabberProcessor.process(WebcamGrabberProcessor.java:149)
    ... 5 more
Exception in thread "webcam-discovery-service" com.github.sarxos.webcam.WebcamException: java.lang.InterruptedException: sleep interrupted
    at com.github.sarxos.webcam.WebcamDiscoveryService.delay(WebcamDiscoveryService.java:278)
    at com.github.sarxos.webcam.WebcamDiscoveryService.run(WebcamDiscoveryService.java:151)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.InterruptedException: sleep interrupted
    at java.lang.Thread.sleep(Native Method)
    at com.github.sarxos.webcam.WebcamDiscoveryService.delay(WebcamDiscoveryService.java:276)
    ... 2 more
Exception in thread "ProcessorThreadFactory" java.lang.NullPointerException
    at com.github.sarxos.webcam.ds.buildin.WebcamGrabberProcessor$StaticProcessor.run(WebcamGrabberProcessor.java:56)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "ProcessorThreadFactory" java.lang.IllegalMonitorStateException
    at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)
    at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source)
    at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
@ghost ghost assigned sarxos Mar 15, 2013
@sarxos
Copy link
Owner

sarxos commented Mar 15, 2013

Hi David,

Thank you for reporting this issue. I will investigate this problem and provide fix when ready.

Take care!

@sarxos
Copy link
Owner

sarxos commented Mar 21, 2013

David,

Can you please try version 0.3.10-RC1 ??

"No camera found" error was caused probably by incorrectly closed device. I tried it on my PC after all changes and I got clean exception. Device has closed properly, but I would like you to verify the patch.

In terms of this issue. I would like to add special check in the code which will block webcam execution while it is already running in separate process. However I need to figure out the best mechanism for doing this. Currently this is controlled in native layer, which can cause unexpected behaviors etc.

@dmarzo
Copy link
Author

dmarzo commented Mar 26, 2013

I try 0.3.10-RC1, exit exception change, but same error "QuickCam for Notebooks Deluxe 0 no image available

sarxos_webcam_capture_fail_onExit
"
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "atomic-processor" java.lang.IllegalMonitorStateException
at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)
at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source)
at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

@sarxos
Copy link
Owner

sarxos commented Mar 26, 2013

Can you please provide detailed steps of how I could reproduce this error? I've tried running the same applet in separate window, but exception was different.

@dmarzo
Copy link
Author

dmarzo commented Mar 26, 2013

  1. Navigate to some page, ej: google.com
  2. Go to applet page, in example index.html
  3. Applet works fine
  4. Push back button in browser (browser navigate to google.com)
  5. Before java console close (2 or 3 seconds), go to applet page
  6. Applet not work

IE 9.0 and windows 7 64 bits

@sarxos
Copy link
Owner

sarxos commented Mar 26, 2013

Ok, I will take a look on this. Thank you!

@sarxos
Copy link
Owner

sarxos commented Aug 8, 2013

Just FYI, I'm still working on this issue, didn't forget about it :)

@rjsc2000
Copy link

Hi

Any news on this issue?

It's happening to me as well

Thanks

@rjsc2000
Copy link

BTW, in the example you use "Webcam.setDriver" but it says is not thread safe?

@sarxos sarxos closed this as completed in 94859e8 Nov 21, 2013
@sarxos
Copy link
Owner

sarxos commented Nov 21, 2013

Hi,

Sorry for no response for some time but I had to test final solution before I comment.

The problem described in this issue arose from the applet lifecycle which is a little bit different than a classic application, however it should work now I believe. I tested this solution with success using Firefox on my 64-bit Linux Ubuntu 12.04. I'm not able to perform tests on Windows currently (had it reinstalled few days ago), so I would appreciate if someone can verify.

Solution is composed of two factors:

  1. Call static Webcam.shutdown() method in Applet destroy(),
  2. Use Applet parameter separate_jvm=true which causes it to be executed in separate JVM process.

Point 1 prevents from having problems when applet is restarted, and 2 do the same for reload operation (see related stackoverflow question). The final applet code embedded in HTML should look like this:

<applet codebase="." archive="applet.jar" code="MyClass.class" width="320" height="240" alt="Applet">
  <param name="separate_jvm" value="true" />
</applet>

Webcam Capture Applet example has been updated. Please let me know if this change fixed the issue. Newest changes are available in SNAPSHOT only. I do not want to release new version before it is tested on Windows first.

Jar with the fix: webcam-capture-0.3.10-20131121.093736-20.jar

@sarxos
Copy link
Owner

sarxos commented Nov 21, 2013

In regards to the Webcam.setDriver(..) method used. It is not thread safe and must not be executed in parallel threads, however there is no need for such operation, because it's usually invoked only once per application execution (mostly in static context).

@sarxos
Copy link
Owner

sarxos commented Nov 21, 2013

Oh, and by the way, I was not able to run this in the applet simulator when executing "reload" operation (all other operations works fine). The problem is that applet GUI does not appear, don't know why, but from the logs I see that underlying webcams are running well, so this must be some other issue I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants