azure-functions-java-worker icon indicating copy to clipboard operation
azure-functions-java-worker copied to clipboard

Support static methods in Java

Open jeffhollan opened this issue 5 years ago • 1 comments

Not sure if there is a reason for this or not but a question came up here on why for every execution we create a new instance of the class that has your function instead of re-using objects across executions. Prevents people for putting instantiation code in the constructor of the class with the intent of re-using. In C# we require it's a static method, but here where we create an object and invoke I wonder if we could allow users to do that. Seems like it'd be a nice experience.

I believe this may be the line that would be nice if it said "createIfNotExists" type logic.

/cc @brunoborges

jeffhollan avatar Nov 14 '18 13:11 jeffhollan

Going deeper, we should be either explicit of the behavior is set by the worker, or allow the user to dictate the behavior.

  1. Be explicit: enforce that the entry method must be static. This can be verified by the Maven plugin and then double-checked by the worker during runtime.

This would enforce the developer to clearly understand the behavior, and then it would be able to circumvent and implement specific needs (e.g. shared objects).

  1. Allow user to define behavior: if the developer sets a method as static, then of course no new object is created because that's a static method. But the problem is that it requires developer to define everything else as static (e.g. objects used within the function method). If the developer sets a method as non-static, we could provide an @Annotation that would indicate whether objects should be reused or not.

brunoborges avatar Nov 16 '18 12:11 brunoborges