Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/main/java/com/taobao/gecko/core/nio/impl/SelectorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import java.io.IOException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.taobao.gecko.core.config.Configuration;
import com.taobao.gecko.core.core.EventType;
import com.taobao.gecko.core.core.Session;
Expand Down Expand Up @@ -63,8 +63,10 @@ public SelectorManager(final int selectorPoolSize, final NioController controlle
}
this.dividend = this.reactorSet.length - 1;
}

private volatile boolean started;

//SelectorManager status: new -> started -> stopped
private volatile boolean started = false;
private volatile boolean stopped = false;


public int getSelectorCount() {
Expand All @@ -76,7 +78,8 @@ public synchronized void start() {
if (this.started) {
return;
}
this.started = true;
this.started = true;
Copy link
Owner

Choose a reason for hiding this comment

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

缩进不正确。

this.stopped = false;
for (final Reactor reactor : this.reactorSet) {
reactor.start();
}
Expand All @@ -101,7 +104,8 @@ public synchronized void stop() {
if (!this.started) {
return;
}
this.started = false;
this.started = false;
this.stopped = true;
for (final Reactor reactor : this.reactorSet) {
reactor.interrupt();
}
Expand Down Expand Up @@ -148,7 +152,11 @@ void awaitReady() {
}
catch (final InterruptedException e) {
Thread.currentThread().interrupt();// reset interrupt status
}
}

if (this.stopped) {
throw new IllegalStateException("SelectorManager was stopped");
Copy link
Owner

Choose a reason for hiding this comment

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

似乎静默更好点。

Copy link
Author

Choose a reason for hiding this comment

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

不好意思,不懂,什么静默?

Copy link
Author

Choose a reason for hiding this comment

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

大神看我提的metaq issue:killme2008/Metamorphosis#129
客户端存在进入死循环,不强杀不退出的可能。

我的看法是,既然已经stop了,就不能再继续等,应该直接抛异常了。如果觉得这样不好,那有一种情况一定要抛异常,就是while语句为true,而线程又被interrupt,在这种情况下,状态已经不会变了,只能等整个程序退出。

Copy link
Author

Choose a reason for hiding this comment

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

我们的流集群崩溃,然后任务大面积卡住,哈,监控不全,哪些卡住都不知道

Copy link
Owner

Choose a reason for hiding this comment

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

卡住是个什么概念?

Copy link
Author

Choose a reason for hiding this comment

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

就是java进程不退出,kill命令发出去也不行,一定要kill -9才能杀掉。进程不退,占住metaq,新起来的又消费不了。

}
}
}
}
Expand Down