Developing Apama Applications > Developing Apama Applications in Java > Overview of Apama Java Applications > About event listeners and match listeners > Defining multiple listeners
Defining multiple listeners
A monitor can define any number of event expressions, and create any number of listeners. The following code,
public void onLoad() {
   EventExpression eventExpr1 = new EventExpression("Tick(*, >10.0)");
   EventExpression eventExpr2 =
     new EventExpression("NewsItem(\"ACME\", *)");
 
   eventExpr1.addMatchListener(this);
   eventExpr2.addMatchListener(this);
}
is creating two event expressions, eventExpr1 and eventExpr2. Then each is assigned a match listener, thus activating two distinct listeners. The fact that both are being assigned the same match listener object, i.e. this same object this, is inconsequential. It just means that the same method, the match method of this object, will be called when the correlator detects either of the event expressions.
As already described, creating a listener is an asynchronous operation that returns immediately. In the above code, in practice both listeners are created concurrently. It is not possible for the eventExpr1 listener to trigger before the eventExpr2 listener is created. However, once the enclosing method’s code has completed execution, the listeners can trigger at any time, and independently of each other.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.