legacy-knowledge-base
公開されました Sep. 10, 2025

ConnectionPoolTimeoutException:カスタム開発でHttpUtil.URLtoStringメソッドを使用した場合、プールからの接続を待機するタイムアウト例外が発生する

written-by

Jorge Diaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

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バージョン

解決策

Liferay core の HttpUtil クラスは、内部的に Apache HttpClient ライブラリを利用します。
デフォルトでは、このApache HttpClientライブラリは、以下のような構成になっています:
  • ホストあたりの最大接続数: 2
  • 最大総接続数: 20
  • timeout: 10秒
そのため、ホストへの同時呼び出しが2回以上、またはHttpClientを使用した呼び出しが合計20回以上ある場合、ご報告のエラーが発生します:
Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:313)
カスタム開発でこの問題を回避するためには、HttpClientライブラリの設定値を変更する必要があります。これは、 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.hostcom.liferay.portal.util.HttpImpl.timeout は、特定のホストに対して指定できることに注意してください。例えば、 www.google.comに制限したい場合:
com.liferay.portal.util.HttpImpl.max.connections.per.host[www.google.com]=2

これらのプロパティの設定方法については、次のページで詳しく説明しています:
Warning: これらのプロパティは、LiferayがHttpUtilユーティリティを使用するすべての場所に影響を与えるので、注意し、増加する場合は、新しい値がシステム全体のパフォーマンスに影響しないことを確認してください。

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base