With advent of Lambda Expressions, now Java has the capability to change method bodies dynamically. But a method name and associated parameters are tightly coupled and for every method invocation we need to pass the arguments that correspond to the parameters, along with the method name.

Instead, a prepared method call can provide lot of flexibility in providing parameters. A prepared method call can have two stages:

1.Preparation Stage
2.Actual Invocation

Java Run-time or an application can provide a stack like mechanism to help in taking the parameters during the preparation stage. The preparation stage can start with getting a unique invocation identifier to enable concurrent method invocations on a given method. Then required parameters can be provided for the unique invocation identifier. When all the parameters have been provided, method can be simply invoked. This is quite similar to the prepared statements used in JDBC query executions.

This mechanism is simple and separates the method invocation from the providing the required parameters for the invocation. The mechanism can provide several benefits:

1.The invoking method and the preparing method can be different. In fact, preparation can be delegated to several methods
2. Parameters can be immediately validated, independent of method invocation. When the actual invocation is done, we can be sure that all the parameters are valid
3. Invoking method can provide default values to certain parameters
4. The process can support both, By Value or By Reference argument passing
5. Parameters can be copied from the previous invocation, if required
6. Invoked method can publish parameter requirements, just like the SOA paradigm and the invoking method can look up and discover parameter requirements
7. Invoked method can provide and expose a ready for invocation status and can block invocation based on business requirements
8. The Invoked method can provide and implement a control gate mechanism to limit number of concurrent executions to a given number
9. Invocation can be changed to queue based execution, if required. That means, all invocations can get queued up and executed from the queue

The sequence diagram above illustrates the prepared method call interaction sequence. The Unique Identifier Service and Prepared Parameters Storage Service can be implemented as separate services or can be implemented as part of the invoked method.

Before the provide parameter calls, the invoker can also have a parameter lookup service, if provided by the Prepared Parameters storage service.

Please note the Check Invocation Gate Call just before the Invocation call. The prepared parameters storage service can provide an invocation gate that will be open only when all of the following have been satisfied:

1.The Invoked method is ready for execution
2.All the required parameters have been supplied and they have been validated
3.The concurrency limit of the invoked method has not been reached

A prepared method can be a synchronous call or an asynchronous call. In case of an asynchronous call the Prepared Parameters Storage service can provide an event notification to the invoker.

Just like any other method, the Invoked method can be a stateful method or a stateless method – and it can also implement and provide execution in steps and with each invocation the execution proceed with the next step or it can provide a continued execution from the point of where the previous execution had stopped due to an exception.