【发布时间】:2015-09-23 12:15:01
【问题描述】:
protected void waitAndSweep(String symbol) {
try {
long sweepTime = symbolInfo.getSweepTime(symbol);
long timeSinceLastSweep = System.currentTimeMillis() - sweepTime;
long waitTime = timeSinceLastSweep >= getInterval() ? 0 : getInterval() - timeSinceLastSweep;
logTradeEvent("waitAndSweep", symbol, "waittime: " + waitTime);
if (waitTime > 0){
Thread.sleep(waitTime);
}
callSweep(symbol);
}catch (InterruptedException e) {
Thread.currentThread().interrupt();
}catch (Exception e) {
logEvent(StrategyEntry.ERROR, "waitAndSweep", symbol,
"Exception caught...", e);
}
}
当它处于休眠状态时(Thread.sleep),如何中断这个线程,使其退出waitandSweep方法?
private void replace(){
// interrupt the thread;
// call waitandsweep again here;
waitandsweep(symbol)
【问题讨论】:
-
也许您应该使用 CountDownLatch 而不是 Thread.sleep() 并中断......或来自并发命名空间的其他方式。
-
你想要达到的目标
标签: java multithreading interruption