?
Solved

How can I achieve this?

Posted on 2004-04-25
5
Medium Priority
?
208 Views
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?

thanks.
0
Comment
Question by:ggyao2003
[X]
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
5 Comments
 
LVL 9

Accepted Solution

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

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

http://www.javaworld.com/javaworld/jw-10-1996/jw-10-howto.html
0
 
LVL 13

Expert Comment

by:Webstorm
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)
          {
                listeners.remove(tl);
          }

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


0
 
LVL 23

Expert Comment

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

http://venus.cs.depaul.edu/Java/chap08.html

R.K
0
 

Author Comment

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

Author Comment

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

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 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