【发布时间】:2016-12-22 09:12:34
【问题描述】:
我在我的 android 代码中实现了 this 类
我在运行方法中做了如下改动(替换为“true”):
@Override
public void run() {
while (!isInterrupted()) {
try {
// A blocking operation. Initiate a ChatManager instance when
// there is a new connection
pool.execute(new ChatManager(socket.accept(), handler));
Log.d(TAG, "Launching the I/O handler");
} catch (IOException e) {
try {
if (socket != null && !socket.isClosed())
socket.close();
} catch (IOException ioe) {
}
e.printStackTrace();
pool.shutdownNow();
break;
}
}
}
我想在关闭应用程序之前停止该线程。所以我实现了 threadName.interrupt();方法。但这不会中断线程。
我实际上对线程池执行器的使用感到困惑。所以我不确定如何有效地做到这一点。如何实现中断该线程?当调用中断方法时,我想关闭套接字,关闭池并停止线程。
【问题讨论】:
标签: android multithreading sockets threadpool