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