Feign線程安全的實例...?我無法找到任何支持此功能的文檔。有沒有人認爲否則呢?Feign threadsafe ...?
這裏是標準的例子貼在github上回購了假死...
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...?
}
}
對於上面的示例...我使用基於spring的組件來突出顯示一個單例。在此先感謝...
建造者成爲原型是有意義的,你不這麼認爲嗎?構建器的目標是創建一個新的不可變對象,以非原子方式設置屬性。正在構建的對象可以是不可變的,最終的和線程安全的。 – Seagull