File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Author

A program with threads behaving differently on two different machines

Fatima Hussain
Greenhorn

Joined: Feb 09, 2011
Posts: 1
Hello,

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: 3099
    
  33

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
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A program with threads behaving differently on two different machines