Thread synchronization problem
From: Vincent Lascaux (lascaux_cash_at_hotmail.com)
Date: 08/31/04
- Next message: Chris Uppal: "Re: 1.5 howto"
- Previous message: Andrea B.: "Waiting for the end of multiple threads"
- Next in thread: Maik Heller: "Re: Thread synchronization problem"
- Reply: Maik Heller: "Re: Thread synchronization problem"
- Reply: John C. Bollinger: "Re: Thread synchronization problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Chris Uppal: "Re: 1.5 howto"
- Previous message: Andrea B.: "Waiting for the end of multiple threads"
- Next in thread: Maik Heller: "Re: Thread synchronization problem"
- Reply: Maik Heller: "Re: Thread synchronization problem"
- Reply: John C. Bollinger: "Re: Thread synchronization problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|