-
Notifications
You must be signed in to change notification settings - Fork 111
SelectorManager增加stopped状态 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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() { | ||
|
|
@@ -76,7 +78,8 @@ public synchronized void start() { | |
| if (this.started) { | ||
| return; | ||
| } | ||
| this.started = true; | ||
| this.started = true; | ||
| this.stopped = false; | ||
| for (final Reactor reactor : this.reactorSet) { | ||
| reactor.start(); | ||
| } | ||
|
|
@@ -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(); | ||
| } | ||
|
|
@@ -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"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 似乎静默更好点。
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不好意思,不懂,什么静默?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 大神看我提的metaq issue:killme2008/Metamorphosis#129 我的看法是,既然已经stop了,就不能再继续等,应该直接抛异常了。如果觉得这样不好,那有一种情况一定要抛异常,就是while语句为true,而线程又被interrupt,在这种情况下,状态已经不会变了,只能等整个程序退出。
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我们的流集群崩溃,然后任务大面积卡住,哈,监控不全,哪些卡住都不知道
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 卡住是个什么概念?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 就是java进程不退出,kill命令发出去也不行,一定要kill -9才能杀掉。进程不退,占住metaq,新起来的又消费不了。 |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缩进不正确。