Identify Java Callback
A listener and callback mechanism is a common pattern in many places in Java.

The logical place to look for examples is in the Swing API. Will get back to that in a second, but, there are two items that are useful first:


Instead of using an int value to track the source of the event/Task, you should use the task itself.

   public void onResult(String result){
     myListener1.onResult(this, result);
   }

The Listener itself should implement an interface, something like: TaskResultListener:

 public interface TaskResultListener {
     public onResult(Task task, String result);
 }


and the constructor for the Task should take an instance of a TaskResultListener instead of a MyListener1


For examples of how this is used, consider the ActionListener interface and usage in Swing:


ActionListener
Example implementation of ActionListener: TextAction
Example component that calls-back to an ActionListener: JButton / AbstractButton


In the Swing API, it is common to have support for multiple listeners. You have just one. That is OK.