0

I am having a jsp which makes 25 hl7 hapi fhir calls asynchronously using dstu2. As suggested in best practices, I am creating the fhir context once using static loading and reusing it in every service call. However, service calls fail intermittently with the below stack trace: (I initialized the fhir context for every service call and this issue gets resolved. However, this is slowing down the calls. Could someone help me with any alternative approaches or tell me what I am doing wrong)

Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool

public class MyFHIRContext{

public static FhirContext ctx;

static{
    ctx = FhirContext.forDstu2();
    ctx.getRestfulClientFactory().setSocketTimeout(60 * 1000); 
    ctx.getRestfulClientFactory().setConnectTimeout(60 * 1000); 
    ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
}

}

calling code: IGenericClient client = MyFHIRContext.ctx.newRestfulGenericClient("server url");

1 Answers1

1

The exception suggests that your connection pool is not big enough to support that many overlapping requests.

You could either make the pool bigger or, better, reduce the number of requests by issuing them all (or groups of them) as batch requests - see http://hl7.org/fhir/DSTU2/http.html#transaction for the details.

We make extensive use of batch requests in our FHIR clients to good effect.