commercetools / commercetools/commercetools-sdk-java-v2

Consistency in CtOkHttp4Client ExecutorService usage

Aperta
#569 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Java
Stelle
47
Fork
21
Merge medio
9g 13h
PR unite (30g)
4

Descrizione

Hey.

We're evaluating the usage of Virtual Threads with `Executors.newVirtualThreadPerTaskExecutor();`.

I've noticed that there's an inconsistency in the usage of `ExecutorService executor` in `CtOkHttp4Client`:

```java

public CtOkHttp4Client(final ExecutorService executor) {
super(executor);
okHttpClient = clientBuilder.get().dispatcher(createDispatcher(executor, MAX_REQUESTS, MAX_REQUESTS)).build();
}

public CtOkHttp4Client(final ExecutorService executor, final BuilderOptions options) {
super(executor);
okHttpClient = options.plus(clientBuilder.get().dispatcher(createDispatcher(MAX_REQUESTS, MAX_REQUESTS)))
.build();
}

public CtOkHttp4Client(final ExecutorService executor, final int maxRequests, final int maxRequestsPerHost) {
super(executor);
okHttpClient = clientBuilder.get()
.dispatcher(createDispatcher(executor, maxRequests, maxRequestsPerHost))
.build();
}

public CtOkHttp4Client(final ExecutorService executor, final int maxRequests, final int maxRequestsPerHost,
final BuilderOptions options) {
super(executor);
okHttpClient = options
.plus(clientBuilder.get().dispatcher(createDispatcher(executor, maxRequests, maxRequestsPerHost)))
.build();
}

```

The second constructor doesn't reuse the passed `executorService` when creating the dispatcher, while all others that get the same argument do.

It just so happens that this one would be the ideal one for us 🤠.

Is there a reason for this, or is it an oversight?

Besides this, any thoughts or recommendations on using the Virtual Threads executor with the SDK?
Maybe you've already done experimenting on your end? Is the SDK prone to [Thread Pinning](https://docs.oracle.com/en/java/javase/21/core/virtual-threads.html#GUID-704A716D-0662-4BC7-8C7F-66EE74B1EDAD)?

Thanks.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia individuando CtOkHttp4Client e confrontando i quattro costruttori mostrati nell’issue, in particolare il modo in cui createDispatcher riceve l’ExecutorService. Verifica se il costruttore di BuilderOptions debba usare in modo coerente l’executor passato, quindi aggiungi o aggiorna la copertura se il repository contiene test pertinenti; il lavoro è completo quando i costruttori presentano un comportamento coerente e verificato dell’executor.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
api
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.