How can I achieve this?

Posted on 2004-04-25
Last Modified: 2010-03-31
I have a class "task", which has a method called "evaluate()". When this method is called and there is a state change, this Task will notify other Tasks. (The other tasks would in turn evaluate and notify some other tasks if evaluation return true).

my preliminary idea is to use thread's notification methods. But is there any other easier or more neat way to accomplish this?

Question by:ggyao2003
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

mmuruganandam earned 125 total points
ID: 10915942
You have Observer and Observable

Have a look at this... for more information..
LVL 13

Expert Comment

ID: 10916600
Hi ggyao2003,

You can define a listener interface, for example:

    public interface TaskListener
         public void notifiedByTask(Task source  /* , ... other needed parameters */ );

And implements this interface in your task class:

    public class Task
    implements TaskListener
          public void notifiedByTask(Task source  /* , ... other needed parameters */ )

          private Vector listeners=new Vectors(); // keep listener references

          public void addTaskListener(TaskListener tl)
                if (!listeners.contains(tl)) listeners.add(tl);

          public void removeTaskListener(TaskListener tl)

          private void notifyListeners()
                int nb=listeners.size();
                for (int i=0;i<nb;i++)
                      ( (TaskListener)listeners.elementAt(i) ).notifiedByTask(this, ... );

LVL 23

Expert Comment

ID: 10916671
try here you will get lot of stuff...


Author Comment

ID: 10922643
webstorm's advice is the easiest to implement in my case. It is really really simple.

Author Comment

ID: 10922672
I made a mistake in my previous post. It should be "mmuruganandam" instead of "webstorm".
But webstorm did gave a great suggestion!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question