> I got into an infinite loop problem when trying to do the following:
I doubt it. There's not quite enough here to do anything at
all, much less do something forever. Lucky for you, I've been
practicing my mind-reading recently. (It's a key skill for
customer support.)
> // Result
> public class Result
[quoted text clipped - 29 lines]
> }
> }
Notice that since neither Result nor ProblematicConstruct
has any reference to Task, there's no way Task can have
any influence on what's shown here.
> // ProblematicConstruct
> public class ProblematicConstruct implements Listener
[quoted text clipped - 11 lines]
> }
> }
Your ProblematicConstruct implements listener, and contains
an instance of Result, to which you have can add Listeners.
Let's say you've done something (not shown here) equivalent
to
this.result.add(this);
And you call add("test") on that instance of ProblematicContruct.
(Which I'll call "pc".)
pc.add("test");
--> pc.result.add("test");
-----> pc.add("test"); // Because pc is in results listener list.
---------> pc.result.add("test");
-----------------> pc.result.add("test");
And so on forever.
> Can some one gives some advice or help on how to resolve it? Since
> there is not way to restrict people from doing the above Problematic
> construct.
Are you asking how you can prevent future implementors
of Listener from making a similar mistake, and creating
an infinite loop? You can't. You can't prevent them from
calling Thread.stop(), either.(*)
If you're writing a simple event handler / callback system,
you should ignore the possiblity completely. It's not
your problem.
If you're building an industrial-strength plug-in system...
maybe build something simpler first.
More unsolicited advice: One simple way to improve the
code you posted is to delete all the comments.
(*) Perhaps you have a solution to this, say, involving the
SecurityManager. I don't care.

Signature
Mark Jeffcoat
Austin, TX
> Hi all,
>
> I got into an infinite loop problem when trying to do the following:
Y'know, I was happy to contribute an answer to this exact same question that
you posted on clj.help as "A design and coding question: If some1 can help"
until I saw it multiposted on clj.programmer and realized that I had wasted my
effort. I was disappointed.
Don't multipost. It fragments the thread and makes it impossible for people in
one newsgroup to see answers already provided in another. It is a disincentive
for people to answer when you multipost because it frustrates them. Cross-post
instead.
-- Lew