Re: Thread synchronization problem
From: Vincent Lascaux (nospam_at_nospam.org)
Date: 09/02/04
- Next message: Thomas: "Problem serializing a String[] over RMI"
- Previous message: Joop Kaashoek: "Re: JSTL commands do not work"
- In reply to: John C. Bollinger: "Re: Thread synchronization problem"
- Next in thread: Chris Uppal: "Re: Thread synchronization problem"
- Reply: Chris Uppal: "Re: Thread synchronization problem"
- Reply: John C. Bollinger: "Re: Thread synchronization problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 2 Sep 2004 00:39:48 +0100
> I cannot offer reliable design advice without knowing what requirements
> the design is supposed to satisfy. You have described specific actions
> that you want your code to perform. Fine, but that's not a design-level
> issue. If you want design advice then I need a higher-level picture.
Sorry about that
The Data class stores some informations that are downloaded from a computer
above the network.
I have in two data classes: one container (Datas) and the actual data (Data)
Datas acts as a map<string, Data>
Datas offers methods such as size(), getByName(string), iterator(),
add(string, Data), remove(string), removeAll()
Data offers also several methods to work (read and modify) the data
contained (I dont think it is necessary to describe the whole context).
When I ask to download a Datas object, I download only the list of names,
and dont want to download the actual content of the Data object.
When I ask to download a Data object, the information is retrieved from the
network.
These two objects are used rather intensively in the application (the only
purpose of this application is in fact to manage these datas).
In my first code, I checked whether the data was empty every time I accessed
it (like every time I did size(), I first checked and downloaded the Datas
object if it was empty). It was fine while the application was small enough,
but soon I forgot to download at some locations in the code, and maintaining
that became quite complex.
So my idea was to move this "check and download if necessary" procedure
inside the Datas and Data object. They would always be considered as not
empty for the user of the table, and when the first method is called, it
would download the data. That's where I am, with my synchronization problem.
> I think it's needlessly complex, and may not satisfy your requirements.
> Earlier you wrote that Data's methods must invoke assertNotEmpty(),
> which they do not do in this design. If those methods cannot perform
> meaningful and appropriate work on an empty instance (or one in the
> process of being downloaded) then this design cannot work. If they
> _can_ perform appropriate work under those circumstances then you have
> not correctly characterized your problem.
The Data object cannot perform meaningful and appropriate work on empty
instance.
The idea behind this design is that if you use the Data object, then you are
responsible for downloading it if it is empty, before accessing any of the
methods.
The DataAccessor is there to ensure that for you, checking if the data has
been previously downloaded before accessing it in any way.
I agree this is complex, and I would like a more simple solution...
>
> From your example above, it seems like you are trying to implement a
> version of the Flyweight pattern. Perhaps you will find some useful
> advice if you know the name of what you're trying to do. On the other
> hand, it may be that an altogether different strategy would be better --
> I just can't say because I don't know _why_ you are doing what you are
> doing.
I'm not sure about the Flyweight pattern. Looking through google, it looks
like it is a pattern to share some common information among several objects.
That doesnt seem to be what I want to do
-- Vincent
- Next message: Thomas: "Problem serializing a String[] over RMI"
- Previous message: Joop Kaashoek: "Re: JSTL commands do not work"
- In reply to: John C. Bollinger: "Re: Thread synchronization problem"
- Next in thread: Chris Uppal: "Re: Thread synchronization problem"
- Reply: Chris Uppal: "Re: Thread synchronization problem"
- Reply: John C. Bollinger: "Re: Thread synchronization problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|