You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by pu...@innet.be on 2000/08/03 13:52:15 UTC

Bugfix

Hi,

A small bugfix, but rather hard to find (please excuse me if
it was already documented, I didn't take the time to check).
When processing an fo file containing more than one inline-graphic
I encountered a deadlock situation in the following code:

public GifJpegImage(String href, int x, int y, int w, int h)
{
	this.ref = href;
	this.X = x;
	this.Y = y;
	this.pixelheight = -1;
	this.pixelwidth = -1;
	try
	{
		URL url = new URL(href);
		ImageProducer ip = (ImageProducer) url.getContent();
		FopImageConsumer consumer = new FopImageConsumer(this);
		ip.startProduction(consumer);
		synchronized (imageWait)
		{
====> deadlock here			imageWait.wait();
		}
...rest of code omitted

The deadlock occurs because the notification for the second and
subsequent images occurs before the startProduction method returns
(due to thread scheduling...)
Often this will not occur for the first image because some classes
and background threads must be initialized once. But once they
are there, processing
an image goes faster and the FopImageConsumer gets notified before
the call to imageWait.wait() takes place.

The fix : put ip.StartProduction() in the protected block of
code

		FopImageConsumer consumer = new FopImageConsumer(this);
		synchronized (imageWait)
		{
			ip.startProduction(consumer);
			imageWait.wait();
		}

This will ensure that the notification operation can only take
place when the wait() released the lock on imageWait. Here is
the code from FopImageConsumer.imageComplete
I did not modify it.

		public void imageComplete(int status)
		{
// ===> may only enter this code when wait() released the lock
			synchronized (graphic.imageWait)
			{
				graphic.imageWait.notifyAll();
			}
		}


Hope this helps,

Yves Dierick

Senior Software Engineer / IT Architect
Aprico Consultants

E-mail:ydierick@aprico-consult.com


-----
Sent using MailStart.com ( http://MailStart.Com/welcome.html )
The FREE way to access your mailbox via any web browser, anywhere!