Re: Using variable or using direct method call
- From: Johan Poppe <jupweb@xxxxxxxxx>
- Date: Tue, 31 May 2005 08:10:09 +0200
- wrote:
>and if another thread were to change the parent, will the above fail
>since the method is not synchronized?
>
>Or should I just leave it that way rather than change it to
>getParent().callMethod(...) everytime...
Depends on what you want and what you consider "fail".
Basically, you are talking about a situation where the locally stored
'parent' and the result of getParent() is no longer the same. That
means that
parent.callAnotherMethod()
and
getParent().callAnotherMethod()
will call on different objects. The first variant will call on the
container that was the parent when the method started. The second
variant will call on the container that is the parent right now. I
can't tell you which of the objects you _want_ to call on.
>but doing so is of no use since
>if the parent changes midway, the method's objective will not be met
>since it requires that the parent be the same throughout the method's scope?
If you want to call on the same container object throughout your
method, _and_ you want that object to be the actual parent-container,
then you should synchronize on something.
--
Johan Utne Poppe
.
- References:
- Prev by Date: Re: Java Programming Using Netbeans Tutorial
- Next by Date: Re: Any VoiceXML service providers in UK offering free trial access for developers?
- Previous by thread: Re: Using variable or using direct method call
- Next by thread: Cannot connect socket through socks proxy
- Index(es):
Relevant Pages
|
|