On Thu, 2005-05-12 at 04:26 -0700, Tommy wrote:
> One thing that is still not totally clear is the role of local
> variables.
>
> In the getData() method, there is the data Vector. So given I would not
> make any call to the database via connection, there would not be any
> threading issue since data is not shared between threads.
> Data is a local variable that gets created when the method is called.
> So when different threads call getData(), each gets its own new data
> object.
>
> Is that correct? So could I make the local data Vector into an
> ArrayList and still consider it thread-safe (ignoring the database
> access issue for a while)?
>
This is true. I would make getData() return a Collection (or maybe List
if ordering/indexing matters), and you could then return any kind of
list you like.
The data variable is your new list, you're guaranteed no-one else is
accessing it because you haven't given it to anyone else yet, so you
don't need the overhead of Vector's synchronization (which could be
surprising with a lot of records).
Ross
--
[Ross A. Bamford] [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ +
in