wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes A program with threads behaving differently on two different machines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "A program with threads behaving differently on two different machines" Watch "A program with threads behaving differently on two different machines" New topic

A program with threads behaving differently on two different machines

Fatima Hussain

Joined: Feb 09, 2011
Posts: 1

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:

Thank you very much.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068

Hi Fatima, Welcome to JavaRanch,

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?

Mohamed Sanaulla | My Blog
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
I would certainly add timing measurement to the calls to screen capture and writing.

Without some knowledge of those times you are just blundering in the dark. You could use a toolkit like JAmon or the System current time calls.

I agree. Here's the link: http://aspose.com/file-tools
subject: A program with threads behaving differently on two different machines
Similar Threads
Producer Consumer Controller
Thread interrupt confusion
Is there any problem with this code?
Problem in doing animation using multithreading
Stop a thread executing sequential lines of code