I am working on a screen recording application. It uses three different kinds of threads to capture screen shots, store them in files and upload them to the server where the images are merged into a video.
The problem is this application is behaving differently on my desktop Dell machine and on my Dell Laptop, both have Windows on them.
The video that is recorded on the desktop PC misses frames. It approximately has 1 frame per 2 seconds. However, the video on laptop has more frames per second
but fails to respond to the the interrupt when video recording is stopped and keeps recording for a couple of seconds afterward. I am quite surprised by this behavior of the same code on two different machines. Also, as per code the application should record far more frames per second because it sleeps for 1 ms and resumes. Any insight into this would be highly appreciated.
Some of the code is below:
Screen is captured through a class which has a thread running in it. The code is similar to this:
Images are written to files by a writer class that implements Runnable interface. The code is similar to this:
Files are streamed to the server by another class Streamer which implements Runnable:
All these threads are started after user starts recording by pressing a button:
After the stop button is pressed, threads are interrupted and stopped:
One thing is for sure- Nothing can be said about the Thread behavior- There might be a case where your Writer thread runs for longer time but the Screencapture thread runs for a shorter time. Its all JVM specific. One thing which can be done is that- You can have thread communication using- wait and notify and there by- try to create some sort of order between the thread executions.
Also why is the Thread.sleep(1) put in a synchronized block only for Streamer thread?