myeclipse web 项目怎么设置过一段时间后项目自动停止。项目框架(struts spring mybaits ) tomcat6.0 求大神指点。。。
3条回答 默认 最新
洗洗脚泡泡澡 2016-06-27 08:55关注System.exit(0);一句话就好了啊,项目启动计时,自己定时执行这句话,服务器就关掉了。
public class Task { public static void main(String[] args) { final long timeInterval = 1000; Runnable runnable = new Runnable() { public void run() { while (true) { try { Thread.sleep(timeInterval); } catch (InterruptedException e) { e.printStackTrace(); } System.exit(0); } } }; Thread thread = new Thread(runnable); thread.start(); } }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报