Last Friday was a holiday in Ontario so I did not publish a tip of the week. That means this week there will be two tips!! Both tips relate to new function in InfoSphere Streams 3.2.1.

Tip #1: @SharedLoader

There was a new annotation added for Java operators: @SharedLoader in the 3.2.1 version of Streams. This annotation causes operators (with the annotation) in the same PE that have the same dependencies to share a class loader. Prior to 3.2.1 each operator in a PE had its own class loader. Why did we add the annotation?? By using a common class loader, common dependencies are only loaded once. There is also a limitation in Java that a native library could only be loaded into one class loader. Allowing operators to share a class loader enables operators that load the same native library to be fused into a PE.

For more information refer to @SharedLoader summary information in the Knowledge Center.

Tip #2: Updating a map within a for loop

This code does not work:

mutable map myMap = {.......};
for (int32 index in myMap) {
  myMap[index] = "someNewValue";   // This is an error because within the for loop myMap is immutable

In InfoSphere Streams 3.2.1 a new function called keys was introduced. This code does work:

for (int32 index in keys(myMap)) {
    myMap[index] = "someNewValue";  // Now okay because the list returned by keys is what we are iterating over

The only caveat is that the behavior is undefined when adding or removing elements in the map within the loop.

Bonus Tip: Check out What’s New

I feel bad about missing a week so here is a bonus tip…

What’s New contains information about new features in InfoSphere Streams. Always check this out to see the latest features.

Join The Discussion