请问谁有定时任务的源程序(比如每过1秒就打印“hello”),在线等!!!急急!!! 你可以看一下java.util.TimerTask对象的应用! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class FileMonitor extends Thread { public FileMonitor() { } public static Log4J log4j = new Log4J(); Object cl; String action; int timeout; public FileMonitor(Object cl, String action, int timeout) { this.cl = cl; this.action = action; this.timeout = timeout; } public void run() { while (true) { Object o = new Object(); synchronized (o) { try { o.wait(timeout); Method method = cl.getClass().getMethod(action, null); method.invoke(cl, null); } catch (Exception ex) { log4j.error.error("run() : " + ex.getMessage()); ex.getMessage(); } } } }}public class Main {public static void main(String[] args) throws Exception { Main main = new Main(); new FileMonitor(main, "FileMonitor", 10000).start();}} import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JApplet;import javax.swing.Timer;/** * Descripton TODO * * @author FuYao */public class TimerTest extends JApplet { public void init() { Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println("hello"); } }); timer.start(); }} import java.util.Timer;import java.util.TimerTask;/** * Descripton TODO * * @author FuYao */public class TimerTest { public static void main(String[] args) { Timer timer=new Timer(); timer.scheduleAtFixedRate(new TimerTaskImpl(),1000,1000); }}class TimerTaskImpl extends TimerTask { /* (non-Javadoc) * @see java.util.TimerTask#run() */ public void run() { // TODO Auto-generated method stub System.out.println("hello"); } } 大大们帮我看一下这段xml代码有什么问题好吗 mybatis急用 Crawler4j该如何用 做一个食堂网上订饭系统使用jsp还是asp好? struts2.0 validation 编译servlet错了 如何创建不同连接的事务的问题,请大家帮忙 刚学webwork一个错误,帮忙看看 HIBERNATE的一个业务逻辑类中有该类自己类型的属性,该如何支持? 国内有提供Web服务的网站吗? 100分求STRUTS连接数据库配制 struts动态显示的问题
extends Thread {
public FileMonitor() {
} public static Log4J log4j = new Log4J();
Object cl;
String action;
int timeout; public FileMonitor(Object cl, String action, int timeout) {
this.cl = cl;
this.action = action;
this.timeout = timeout;
} public void run() {
while (true) {
Object o = new Object();
synchronized (o) {
try {
o.wait(timeout);
Method method = cl.getClass().getMethod(action, null);
method.invoke(cl, null);
}
catch (Exception ex) {
log4j.error.error("run() : " + ex.getMessage());
ex.getMessage();
}
}
}
}
}
public class Main {
public static void main(String[] args) throws Exception {
Main main = new Main();
new FileMonitor(main, "FileMonitor", 10000).start();
}
}
import java.awt.event.ActionListener;import javax.swing.JApplet;
import javax.swing.Timer;/**
* Descripton TODO
*
* @author FuYao
*/
public class TimerTest extends JApplet { public void init() {
Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("hello");
}
});
timer.start();
}}
import java.util.TimerTask;
/**
* Descripton TODO
*
* @author FuYao
*/
public class TimerTest {
public static void main(String[] args) {
Timer timer=new Timer();
timer.scheduleAtFixedRate(new TimerTaskImpl(),1000,1000);
}}class TimerTaskImpl extends TimerTask { /* (non-Javadoc)
* @see java.util.TimerTask#run()
*/
public void run() {
// TODO Auto-generated method stub
System.out.println("hello");
}
}