Java Callout Lifecycle

Not applicable

What is the lifecycle of a java callout object?

- Is one created and run once per request (afterwards able to be garbage collected)?

- Is one created and re-used for multiple requests? If so is it locked or do we need to ensure thread safety?

- Is a pool of them created and re-used?

I wasn't able to find this information in the java callout related docs:

- http://docs.apigee.com/api-reference/content/how-create-java-callout

- http://docs.apigee.com/api-services/reference/java-callout-policy

Thanks.

Solved Solved
5 5 1,311
1 ACCEPTED SOLUTION

the java callout class is instantiated once, and invoked multiple times, once for each request.

The callout class gets its own classloader.

Multiple concurrent requests will result in multiple threads calling into the execute() method, concurrently. The execute() method must be thread safe. Apigee Edge does not create a pool of objects, and does not lock or synchronize access to the callout object or the execute() method.

Does this answer the question?

View solution in original post

5 REPLIES 5

Hello @Jay Anderson please find my answers below:

- Is one created and run once per request (afterwards able to be garbage collected)?

Answer: This is correct.

- Is one created and re-used for multiple requests? If so is it locked or do we need to ensure thread safety?

Answer: NA

- Is a pool of them created and re-used?

Answer: I did not quite understand this. An object is created when as and when the request comes in.

Hope this helps.

Is it loaded with a new classloader each time? For instance would singleton objects called from the com.apigee.flow.execution.spi.Execution instance live beyond the single call or are they re-loaded each time?

the java callout class is instantiated once, and invoked multiple times, once for each request.

The callout class gets its own classloader.

Multiple concurrent requests will result in multiple threads calling into the execute() method, concurrently. The execute() method must be thread safe. Apigee Edge does not create a pool of objects, and does not lock or synchronize access to the callout object or the execute() method.

Does this answer the question?

Very helpful. Thanks.

Hi Dino,

Just wanted to reconfirm on the above point you mentioned, suppose we create a class "A" and configure the same in java callout in Apigee. Now will each request to the proxy having the java callout will create an instance of class A , or as mentioned by you above, class A will be instantiated only once and the execute method within the class will be invoked multiple time for each request. can you please elaborate on the same.

Because we have a case where in we are creating an HTTPClient request to an NTLM protected endpoint, our idea is to have only one instance of HTTPClient , do we need to explicitly implement singleton design so that only one instance of HTTPClient at all point of time.