Functions may be declared and called within the APL code using normal Java syntax.
Info |
---|
title | Example - Declaring functions |
---|
|
Code Block |
---|
int addNumbers (int a, int b){
return a + b;
} consume {
debug( "1 + 1 = " + addNumbers( 1, 1 ) );
} |
|
To declare functions with no return value, the void keyword should be used.
The Synchronized Keyword
In order to support multi-threading, functions updating global variables within realtime workflows must be made thread-safe. To achieve this, the function name is preceded with the synchronized
keyword:
Info |
---|
title | Example - Using the synchronized keyword |
---|
|
Code Block |
---|
synchronized int updateSeqNo(){
seqNo = seqNo +1;
return seqNo;
} |
|
It is possible to read global variables from any function block. However, to avoid race conditions with functions updating the global variables, they must only be accessed from within synchronized
functions.
Note |
---|
|
The synchronized keyword is ignored when used in batch agents. |
To declare functions with no return value, the void
keyword is used.