Feignスレッドのインスタンスは安全ですか?私はこれをサポートする文書を見つけることができませんでした。そこにいる人は他に何か考えますか?ここでFeignはスレッドセーフなのですか?
を装うための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...?
}
}
上記の例では、私はシングルトンを強調するために春に基づいたコンポーネントを使用しました。事前にありがとうございます...
ビルダーがプロトタイプであることは意味があると思いますか? Builderの目標は、非永続的にプロパティを設定して新しい不変オブジェクトを作成することです。構築されているオブジェクトは、不変、最終、スレッドセーフである可能性があります。 – Seagull