【发布时间】:2012-08-31 06:13:50
【问题描述】:
这是我的 Runnable 对象(在另一个类中):
private class StopFileCopy implements Runnable
{
ObjectInputStream st;
public Runnable(ObjectInputStream st)
{
this.st = st;
}
public void run()
{
if(st.read())
stopWritingToFile = true; // stopWritingToFile is an instance variable of the
// class that contains this StopFileCopy class
}
}
现在的问题是整数可能会或可能不会写入流“st”。如果没有,那么我需要立即从类外停止此 StopFileCopy 对象。我怎样才能做到这一点?
【问题讨论】:
-
为什么不直接停止 Runnable 本身?
-
@biovamp ,st.read() 方法继续尝试从流“st”中读取一个整数。我不知道如何通知 StopFileCopy 类 run() 方法应该停止尝试从流中读取。
标签: java multithreading stream runnable