我有一个名为timer
:
timer.schedule(new task1(), 1000*minutes);
任务:
class task1 extends TimerTask {
@Override
public void run()
{
try {
task();
} catch (SAXException ex) {
Logger.getLogger(task1.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(task1.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(task1.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(task1.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(task1.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void task() throws SAXException, ParserConfigurationException, IOException, URISyntaxException, InterruptedException {
Pinner_xml t = new Pinner_xml();
t.xml(frame.t1.getText());
frame.output.append("task 1 \n");
System.out.println("task 1 is running");
}
}
frame
是我的框架名称,output
是一个文本框。为什么我在Netbeans的输出对话框中运行任务全部是“任务1正在运行”并且任务只运行一次。