mirror of
https://gitee.com/dromara/hutool.git
synced 2025-11-24 08:33:22 +08:00
fix doc
This commit is contained in:
@@ -21,13 +21,25 @@ import java.io.Serializable;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地端口生成器<br>
|
* 本地端口生成器(LocalPortGenerator)。
|
||||||
* 用于生成本地可用(未被占用)的端口号<br>
|
* 用于从指定起点开始递增探测一个当前“可用”的本地端口。探测通过短暂绑定
|
||||||
* 注意:多线程甚至单线程访问时可能会返回同一端口(例如获取了端口但是没有使用)
|
* {@link java.net.ServerSocket}(以及可选 UDP DatagramSocket)完成,但不会真正占用端口。
|
||||||
|
* <p>注意:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>该方法执行的是端口“探测”,非“分配”,返回端口不保证实际使用时仍然可用。</li>
|
||||||
|
* <li>存在 TOCTOU(检测到使用之间)竞态,多线程下可能返回同一端口。</li>
|
||||||
|
* <li>UDP 探测可能导致误判(TCP 可用但 UDP 被占用)。</li>
|
||||||
|
* <li>不适合作为生产级端口分配策略,推荐使用 {@code new ServerSocket(0)}。</li>
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Looly
|
* <p>TODO 未来版本计划:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>提供真正可靠的端口获取实现(绑定即占用,避免竞态)。</li>
|
||||||
|
* <li>优化探测策略,减少不必要的 UDP 检测。</li>
|
||||||
|
* <li>提供更安全的随机端口生成 API。</li>
|
||||||
|
* </ul>
|
||||||
|
* @author looly
|
||||||
* @since 4.0.3
|
* @since 4.0.3
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class LocalPortGenerator implements Serializable{
|
public class LocalPortGenerator implements Serializable{
|
||||||
@Serial
|
@Serial
|
||||||
|
|||||||
Reference in New Issue
Block a user