英文:
RestTemplate Connection Pooling Logs
问题
有没有办法找出或记录 RestTemplate 连接池的详细信息,我想确保 RestTemplate 正在使用自定义配置的连接池。
英文:
Is there any way to find out or log the details of RestTemplate connnection pool, i want to make sure that RestTemplate is using custom connection pool configured.
答案1
得分: 1
你可以在你的配置文件中为RestTemplate所在的包启用DEBUG级别的日志记录:
logging:
level:
org.springframework.web: DEBUG
并且不要忘记自定义你的log4j2.xml:
<Console name="Console" target="SYSTEM_OUT"
ignoreExceptions="false">
<PatternLayout
pattern="%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
</Console>
另一种方法是,在你的RestTemplate上添加一个断点,这样你就可以查明它是否正在使用你的自定义连接池。
希望对你有帮助。
英文:
You can activate DEBUG level logging for RestTemplate containing package on your configuration file :
logging:
level:
org.springframework.web: DEBUG
And don't forget to cutomize your log4j2.xml:
<Console name="Console" target="SYSTEM_OUT"
ignoreExceptions="false">
<PatternLayout
pattern="%d{yyyy-MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
</Console>
Another approach, you can add a break point on your RestTemplate and hence you can figure out whether it's taking your custom connection pool or not.
Hope that helps.
答案2
得分: 1
当使用自定义连接池时,就像我使用的apache HttpClientConnection一样,apache提供了PoolingHttpClientConnectionManager类,其中包括一些有用的方法,如getTotalStats(),可以满足我的池统计日志需求。
@Autowired
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager;
poolingHttpClientConnectionManager.getTotalStats();
英文:
When using custom connection pool. Like apache HttpClientConnection which i used, apache provides PoolingHttpClientConnectionManager class which comprise of several useful methods like getTotalStats(), fulfilled my logs for pool stats .
@Autowired
PoolingHttpClientConnectionManager poolingHttpClientConnectionManager;
poolingHttpClientConnectionManager.getTotalStats();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论