Ant 任务在 main 方法中正常,但在 Ant 执行期间在确定的行后停止
Ant task goes normal in the main method, but stops after definite line during Ant execution
有谁知道,为什么这样的蚂蚁任务:
public void execute() {
Timer timer = new Timer();
TimerTask action = new TimerTask() {
@SuppressWarnings("ResultOfMethodCallIgnored")
public void run() {
String urlsForCheckPath = arachniBinPath + "urls.txt";
List<String> urlsForCheck;
try {
urlsForCheck = FileUtils.readLines(new File(urlsForCheckPath));
if (urlsForCheck != null) {
for (String urlForCheck : urlsForCheck) {
new File(arachniLogPath).delete();
clearTemporary(urlForCheck);//if something remains after exceptions
logger.info(urlForCheck + " previous log and possibly remaining temporary files deleted.");
checkURL(urlForCheck);
urlForCheck = urlForCheck.replace("/", "-");
convertAndSend(urlForCheck);
clearTemporary(urlForCheck);
logger.info(urlForCheck + " temporary files deleted.");
}
}
} catch (Exception e) {
log(e);
}
}
};
timer.schedule(action, delayBeforeStart);
}
在 main 方法中正常,但在
之后停止
logger.info(urlForCheck + " previous log and possibly remaining temporary files deleted.");
在通过 ant 执行期间没有异常?如何解决?
我认为您应该阅读此答案。
Java: Wait for TimerTask to complete before continuing execution
小例子:
protected final Timer timer = new Timer();
public void execute() {
CountDownLatch latch = new CountDownLatch(1);
timer.schedule(new TimerTask() {
public void run() {
}
}, delayBeforeStart);
try {
latch.await();
} catch (InterruptedException e) {
log(e);
}
timer.cancel();
}
有谁知道,为什么这样的蚂蚁任务:
public void execute() {
Timer timer = new Timer();
TimerTask action = new TimerTask() {
@SuppressWarnings("ResultOfMethodCallIgnored")
public void run() {
String urlsForCheckPath = arachniBinPath + "urls.txt";
List<String> urlsForCheck;
try {
urlsForCheck = FileUtils.readLines(new File(urlsForCheckPath));
if (urlsForCheck != null) {
for (String urlForCheck : urlsForCheck) {
new File(arachniLogPath).delete();
clearTemporary(urlForCheck);//if something remains after exceptions
logger.info(urlForCheck + " previous log and possibly remaining temporary files deleted.");
checkURL(urlForCheck);
urlForCheck = urlForCheck.replace("/", "-");
convertAndSend(urlForCheck);
clearTemporary(urlForCheck);
logger.info(urlForCheck + " temporary files deleted.");
}
}
} catch (Exception e) {
log(e);
}
}
};
timer.schedule(action, delayBeforeStart);
}
在 main 方法中正常,但在
之后停止 logger.info(urlForCheck + " previous log and possibly remaining temporary files deleted.");
在通过 ant 执行期间没有异常?如何解决?
我认为您应该阅读此答案。 Java: Wait for TimerTask to complete before continuing execution
小例子:
protected final Timer timer = new Timer();
public void execute() {
CountDownLatch latch = new CountDownLatch(1);
timer.schedule(new TimerTask() {
public void run() {
}
}, delayBeforeStart);
try {
latch.await();
} catch (InterruptedException e) {
log(e);
}
timer.cancel();
}