問題
com.liferay.portal.kernel.util.HttpUtil の Liferay URLtoString メソッドを使用して、カスタム開発で外部ウェブサービスを呼び出しています。
ConnectionPoolTimeoutExceptionが発生します: 外部ウェブサービスを呼び出すと、タイムアウトによるプールからの接続待ちの例外が発生します:
java.io.IOException: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at com.liferay.portal.util.HttpImpl.URLtoInputStream(HttpImpl.java:1902)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:1588)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:1178)
at com.liferay.portal.util.HttpImpl.URLtoString(HttpImpl.java:1240)
at com.liferay.portal.kernel.util.HttpUtil.URLtoString(HttpUtil.java:315)
[...omitted...]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:313)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:279)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:191)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at com.liferay.portal.util.HttpImpl.URLtoInputStream(HttpImpl.java:1783)
... 235 more
どうすればこのエラーを回避できるのか?
Environment
- 任意のLiferayバージョン
解決策
- ホストあたりの最大接続数: 2
- 最大総接続数: 20
- timeout: 10秒
Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:313)
portal-ext.properties ファイルからプロパティを通して行うことができます:com.liferay.portal.util.HttpImpl.max.connections.per.host=2
com.liferay.portal.util.HttpImpl.max.total.connections=20
com.liferay.portal.util.HttpImpl.timeout=10000
com.liferay.portal.util.HttpImpl.max.connections.per.host と com.liferay.portal.util.HttpImpl.timeout は、特定のホストに対して指定できることに注意してください。例えば、 www.google.comに制限したい場合:com.liferay.portal.util.HttpImpl.max.connections.per.host[www.google.com]=2
これらのプロパティの設定方法については、次のページで詳しく説明しています:
Warning: これらのプロパティは、LiferayがHttpUtilユーティリティを使用するすべての場所に影響を与えるので、注意し、増加する場合は、新しい値がシステム全体のパフォーマンスに影響しないことを確認してください。
追加情報