Skip to content

feat:暂停当前线程依赖库#236

Open
superName-w wants to merge 8 commits intonetease-lcap:mainfrom
superName-w:wgx-thread-util
Open

feat:暂停当前线程依赖库#236
superName-w wants to merge 8 commits intonetease-lcap:mainfrom
superName-w:wgx-thread-util

Conversation

@superName-w
Copy link
Contributor

No description provided.

@github-actions
Copy link
Contributor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 waitThreadWithTimeout 方法中,建议在进入同步块之前检查 timeout 是否有效,以避免不必要的同步开销。

@NaslLogic
    public static Boolean waitThreadWithTimeout(String lock, Long timeout) {
        if (lock == null) {
            log.error("锁对象不能为空");
            return false;
        }
        if (timeout <= 0) {
            log.error("超时时间必须大于0");
            return false;
         }
        synchronized (lock.intern()) {
            try {
                lock.intern().wait(timeout);
                log.info("线程在超时前被成功唤醒");
                return true;
            } catch (InterruptedException e) {
                log.error("带超时的等待线程被中断", e);
                Thread.currentThread().interrupt();
                return false;
            }
        }
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@lyjamare
Copy link
Collaborator

功能及代码已验收,待评分

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments