Re: Using variable or using direct method call



- 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
.



Relevant Pages

  • Re: Shutting down a service
    ... >When one of our services fails on our HPUNIX box we want to be able to ... by an external network-delivered command? ... Write a parent process that will ... is that the process that may fail should not daemonize itself, ...
    (comp.sys.hp.hpux)
  • [PATCH 2/2] function-graph: always initialize task ret_stack
    ... we fail to allocate the ret_stack, and then fail the fork, the ... duplicated the parent and currently points to the parent's ret_stack. ...
    (Linux-Kernel)
  • Re: [why oom_adj does not work] Re: Linux killed Kenny, bastard!
    ... Your Kenny-killer will fail, too. ... Maybe the weight for childs should be ... so killing the parent is the right thing if you ... You can only win by by suspending or killing the factory. ...
    (Linux-Kernel)
  • Re: Can we continue to call ourselves a civilised country?
    ... to ascertain the reason, and if the parent is at fault measures to ... take into care any child that failed. ... *Any* parent can educate a child up to the stage of early high school. ... There may be perfectly valid reasons why a minority of children fail ...
    (uk.legal)
  • Re: DTS package Precedence not working
    ... I guess that means that you cannot easily have a child process which both ... has on-error processing, but which you also want to signal a fail to a parent ... if any other tasks fail. ...
    (microsoft.public.sqlserver.dts)