Thread synchronization problem

From: Vincent Lascaux (lascaux_cash_at_hotmail.com)
Date: 08/31/04


Date: 31 Aug 2004 04:03:44 -0700

Hello,

I have a class that store informations and has an "empty" attribute.
Whenever I want to access this information, I first check if the class
is "empty". If so, I download the information and set the class non
empty. So I have this method:

private synchronized void assertNotEmpty()
{
  if(isEmpty())
  {
    download();
    //now isEmpty() is false
  }
}

The problem is that I now require download to be multi-threaded, and
to access some of the methods of the class (it even access the
assertNotEmpty method since it is reading some informations from the
object after having started the download). This obviously result in a
deadlock.

The simple solution is to remove the synchronized, but then I may (and
this happens because "download" is rather long) download several time
the informations (and I dont want that).

How to solve this kind of problem?

Thank you

-- 
Vincent


Relevant Pages

  • Re: muliple messages
    ... new message and after downloading them into OE, the web mail shows as empty. ... >> should be nothing for Outlook Express to download. ... >> such a folder and you may need to empty that folder. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: I want to download a software, then make a CD image.
    ... First, I use Windows 2000 pro sp4, download the software. ... Download to an empty hard disk, only one partion, save to the disk? ... Download to an empty folder of an empty hard disk, ...
    (microsoft.public.win2000.networking)
  • Re: "Vivisector"
    ... You Are Empty includes StarForce 4 as part of the download. ... I'm getting rid of this game. ...
    (comp.sys.ibm.pc.games.action)
  • Re: Hexadeciaml Error
    ... they all download it from a FTP site each night and then read it ... //convert 5 empty bytes to string ... StreamWriter sw = new StreamWriter; ... It's strange however that you read the same xml on the second shot... ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Thread synchronization problem
    ... > empty. ... > private synchronized void assertNotEmpty() ... > download(); ... > assertNotEmpty method since it is reading some informations from the ...
    (comp.lang.java.programmer)