Является ли экземпляр Feign потокобезопасным...? Я не смог найти никакой документации, подтверждающей это. Кто-нибудь там думает иначе?
Вот стандартный пример, размещенный в репозитории github для Feign...
interface GitHub {
@RequestLine("GET /repos/{owner}/{repo}/contributors")
List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
}
static class Contributor {
String login;
int contributions;
}
public static void main(String... args) {
GitHub github = Feign.builder()
.decoder(new GsonDecoder())
.target(GitHub.class, "https://api.github.com");
// Fetch and print a list of the contributors to this library.
List<Contributor> contributors = github.contributors("netflix", "feign");
for (Contributor contributor : contributors) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}
}
Должен ли я изменить это на следующее... Это потокобезопасно...?
interface GitHub {
@RequestLine("GET /repos/{owner}/{repo}/contributors")
List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
}
static class Contributor {
String login;
int contributions;
}
@Component
public class GithubService {
GitHub github = null;
@PostConstruct
public void postConstruct() {
github = Feign.builder()
.decoder(new GsonDecoder())
.target(GitHub.class, "https://api.github.com");
}
public void callMeForEveryRequest() {
github.contributors... // Is this thread-safe...?
}
}
Для приведенного выше примера... Я использовал компоненты на основе пружины, чтобы выделить синглтон. Заранее спасибо...
Feign.builder()
, не имеет состояния, а любые используемые вами классыParam.Expander
не имеют состояния, вы должны быть в безопасности. - person Shadow Man   schedule 05.04.2018