You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Java Object Semantics

1. Objects will not be re-instantiated/rebuilt unless they have an internal Collection to which they add through and addX method. If you have data structures such as as Map, the map will not be cleared or reconstructed on multiple calls to execute the containing task (i.e., inside a loop).

2. If you have implemented an addX or setX method which takes a field of the parameter object and uses it as a key to an internal map, be careful of the situation in which that field may change (under looping conditions where its value references the environment). For instance:

<for var="i" from="0" to="${max}">
    <declare name="filter" global="true">
       <local-event-filter topic="TROLL-${i}">
	   <event-header-comparator>
		<property-comparator comparator="EQUALS">
		    <property name="component-${i}">
			<value>master</value>
		    </property>
		</property-comparator>
	   </event-header-comparator>
       </local-event-filter>
    </declare>
</for>

It so happens that the <property-comparator>'s method for adding properties takes the property name and uses it as a key to an internal map (e.g., {p.name=p}). This means that the comparator instance (which is static), will have a property with an updated name in the map on each call, but the key will always be component-0. The suggested solution here is to use new:

<for var="i" from="0" to="${max}">
    <declare name="filter" global="true">
      <new>
         <local-event-filter topic="TROLL-${i}">
	   <event-header-comparator>
		<property-comparator comparator="EQUALS">
		    <property name="component-${i}">
			<value>master</value>
		    </property>
		</property-comparator>
	   </event-header-comparator>
         </local-event-filter>
      </new>
    </declare>
</for>
  • No labels