本文整理匯總了Java中java.util.Timer.purge方法的典型用法代碼示例。如果您正苦於以下問題:Java Timer.purge方法的具體用法?Java Timer.purge怎麽用?Java Timer.purge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Timer
的用法示例。
在下文中一共展示了Timer.purge方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: StopTask
import java.util.Timer; //導入方法依賴的package包/類
/**
* 停止當前任務(隻會由button UI觸發, 肯定為當前選中task)
*/
public void StopTask() {
this.taskListModel.MarkTaskStatus(currentSelectTask.id, TaskStatus.STOPPED);
NotifyAllObservers();
// 停止定時抓取任務
Timer timer = ApsvTimerManager.GetTimer(currentSelectTask.id);
if (timer != null) {
timer.cancel();
timer.purge();
}
ApsvTimerManager.ClearStartTime(currentSelectTask.id);
}
示例2: copyInputToOutputStream
import java.util.Timer; //導入方法依賴的package包/類
/**
* This copies the downloaded data from the InputStream to the OutputStream,
* keeping track of the number of bytes that have flowed through for the
* progress counter.
*/
private void copyInputToOutputStream(InputStream input, int bufferSize, OutputStream output)
throws IOException, InterruptedException {
Timer timer = new Timer();
try {
bytesRead = 0;
totalBytes = totalDownloadSize();
byte[] buffer = new byte[bufferSize];
timer.scheduleAtFixedRate(progressTask, 0, 100);
// Getting the total download size could potentially take time, depending on how
// it is implemented, so we may as well check this before we proceed.
throwExceptionIfInterrupted();
while (true) {
int count;
if (input.available() > 0) {
int readLength = Math.min(input.available(), buffer.length);
count = input.read(buffer, 0, readLength);
} else {
count = input.read(buffer);
}
throwExceptionIfInterrupted();
if (count == -1) {
Utils.debugLog(TAG, "Finished downloading from stream");
break;
}
bytesRead += count;
output.write(buffer, 0, count);
}
} finally {
downloaderProgressListener = null;
timer.cancel();
timer.purge();
output.flush();
output.close();
}
}