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");