-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Nathan Zumwalt wrote:
You can't use the synchronized keyword in a variable declaration,
only
in a method delaration. You could make your LinkedList variable
private, create a public synchronized method that "gets" the
variable and only use that method when accessing the LinkedList...
it would amount to the same thing.
-Nathan
Hi,
Sorry, but it actually wouldn't be the same thing. I think it's really
important to realize this. The only thing this would do, is make sure
that only one thread could GET the object at a time, it would not
determine what could be done with it once gotten. For example:
- --THREAD1--
getList().add(x);
- --THREAD2--
getList().add(y);
You could have something like this happen:
- --THREAD1-- --THREAD2--
getList() WAITING
NOT SCHEDULED getList()
add() add()
This satisfies the requirement that only one thread is executing
getList() at a time, but it DOESN'T have any impact on what either
thread does with the List once it's returned.
- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/kB2/wxczzJRavJYRAkqmAJ4sW/83G265OeeGJ7CpkRK3PDzSsgCg9lJI
hepCkjbs3FKJ4/YSPCGn504=
=dJhI
-----END PGP SIGNATURE-----