V
Vincent Lascaux
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
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