Closed schabe77 closed 6 months ago
I fixed it by replacing the rather poor cxf library with jersey client.
thank you for reporting this! Yes, looks like CXF is not thread safe. A fix should be released soon
Thank you. I changed my dependencies this way and it seems to work:
<dependency>
<groupId>com.microsoft.bingads</groupId>
<artifactId>microsoft.bingads</artifactId>
<version>13.0.20</version>
<exclusions>
<exclusion>
<artifactId>cxf-rt-rs-client</artifactId>
<groupId>org.apache.cxf</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
With jersey I don't have these multithreading problems. I'm not sure if it's a good idea to synchronize the access at an unknown amount of positions because a rs-implementation is poorly implemented.
Yeah the standard is also not clear on what should be thread safe or not, looks like there is an open issue regarding this: https://github.com/jakartaee/rest/issues/494
I'm not sure if other implementations are thread safe, so it's probably better to add synchronization around the request()
call as you suggested. 13.0.20.1 has a fix for this.
By default we use CXF since it usually has better performance, but it's true that sometimes we may run into tricky issues like this.
By the way, when using a different RS implementation, we recommend to enable message compression for better performance. For example, this works for Jersey and 13.0.20.1:
GlobalSettings.setHttpClientProvider(new HttpClientProvider()
{
@Override
protected ClientBuilder configureClientBuilder(ClientBuilder clientBuilder) {
return super.configureClientBuilder(clientBuilder)
.register(org.glassfish.jersey.message.GZipEncoder.class)
.register(org.glassfish.jersey.client.filter.EncodingFilter.class);
}
});
After switching to 13.0.20 I sometimes get this the exception
it seems the ProviderFactory isn't thread safe. would it be possible to put the access to WebTarget within a synchronized block?