我希望在 5 分钟后执行一段特定的代码。我如何使用 Java 来做到这一点?
out.println("<HTML>");
out.println("<head>");
//out.println("<frame>");
out.println("<frameset rows=\"80%, *\" frameborder=\"0\" border=\"0\" framespacing=\"0\">");
out.println("<frame src=\"DataCenterImage.html\" target=\"DisplayFrame\">");
//out.println("Hai");
out.println("<frame src= \"unlock.html\" target=\"DisplayFrame\">");
out.println("</frameset>");
out.println("</head>");
out.println("</HTML>");
我希望上述内容在 15 分钟后执行。
最佳答案
在 Java 1.5 及更高版本中,您可以使用 java.util.concurrent
包
ScheduledExecutorService scheduler = Executors.newSingleThreadedScheduledExecutor();
ScheduledFuture<?> f = scheduler.schedule(new Runnable() {
public void run() {
//Code to be executed here
}
}, 15L, TimeUnit.MINUTES);
您可以这样取消执行:
f.cancel(false);
关于java - 在Java中启动定时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/589399/