Domanda

I'm using httpcomponents 4.3.3 to do posts. I would like to name the threads it uses so I can easily see them in a thread dump. Is it possible? I see there's a way to wrap an HttpClient in a FutureRequestExecutionService, and give that a ThreadFactory that will provided named threads. Is there another option? I'm currently creating my HttpClient like so:

httpClient = HttpClients.custom().setRetryHandler(requestRetryHandler).build();
È stato utile?

Soluzione

java.lang.Thread has a setName() method. If the thread you want to name extends Thread, you can call setName("myThread") on it.

EDIT: Based on this suggestion, Alper Akture was able to figure out an actual solution.

ExecutorService has a constructor that accepts a ThreadFactory, and the ThreadFactory can be told to create named threads.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top