Double Buffering Deadlock

E

E. Naubauer

Hello folks, it's me again.


If anyone remembers my "fast jpeg decoding" thread, I partly solved the
Problem by drawing the image via double buffering so I was able to
remove the trackers. If I stick to simply drawing I'm getting almost
real time drawing with one camera. However, another problem has faced:
deadlocks (I think).

As you might remember, my program works as follows:

- 2 threads with network connection read the images from the camera
- if one of the threads receives a new image, he passes it to a canvas
derivate (each thread has its own) and calls
EventQueue.invokeLater(<drawThread>) on a third thread that does nothing
except calling repaint() on the 2 canvases.
- the drawing thread sleeps for about 10 ms after repaint() has returned.
- the update() Method of the Canvas that is drawn draws the image the
canvas had received earlier from it's according thread to the backbuffer
with drawImage. After that, it calls paint() where the backbuffer is drawn.


This is a list of the threads that are present during program execution:

main
Thread-1
AWT-Shutdown
AWT-EventQueue-0
Thread-3
Thread-4
Image Fetcher 0
Image Fetcher 1
Image Fetcher 2
Image Fetcher 3
Thread-0

(according to JProfiler)

Now what happens is that the program tends to freeze after a few seconds.

It mostly seems to occur when the cpu load is high. If, for example,
I have both JPEG reading threads running and both images drawn it will
freeze. If I have both threads reading but only one image drawn, it
works. In the second case, it will freeze if I use JProfiler which takes
a huge load of performance away. It shouldn't be an out of memory error
since the program takes about 100 MB usually and the VM maximum is set
to 256.
At the time it freezes, the number of ImageFetchers goes
significantially up (it usually freezes when Image Fetcher 3 starts to
run). If I call System.gc() manually after the backbuffer has been
drawn, it doesn't crash but becomes very slow.

The hotspots of the app are function calls to:

java.awt.EventDispatchThread.run 49%
java.lang.Thread.sleep 16%
java.awt.Graphics.drawImage 15%



Does anyone have any ideas? Please help me! (and many thanks!)
 
K

Knute Johnson

E. Naubauer said:
Hello folks, it's me again.
- 2 threads with network connection read the images from the camera
- if one of the threads receives a new image, he passes it to a canvas
derivate (each thread has its own) and calls
EventQueue.invokeLater(<drawThread>) on a third thread that does nothing
except calling repaint() on the 2 canvases.
- the drawing thread sleeps for about 10 ms after repaint() has returned.
- the update() Method of the Canvas that is drawn draws the image the
canvas had received earlier from it's according thread to the backbuffer
with drawImage. After that, it calls paint() where the backbuffer is drawn.

This doesn't make any sense and without some code I've got no idea what
you are up to.

I can tell you one thing though, you don't need to use the
EventQueue.invokeLater() to call repaint(). It can be called from any
thread and should be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top