JOB是
@IocBean
public class StockJob implements Job{
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println("任务正在执行,执行时间: " + Calendar.getInstance().getTime());
}
}
Schedule是
private void stockSchedule() throws Throwable{
sf = new StdSchedulerFactory();
// 从工厂里面拿到一个scheduler实例
sched = sf.getScheduler();
// 计算任务的开始时间,DateBuilder.evenMinuteDate方法是取下一个整数分钟
// Date runTime = DateBuilder.evenMinuteDate(new Date());
// 真正执行的任务并不是Job接口的实例,而是用反射的方式实例化的一个JobDetail实例
job = JobBuilder.newJob(StockJob.class).withIdentity("job1", "group1").build();
// 定义一个触发器,startAt方法定义了任务应当开始的时间
// Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").startAt(runTime).build();
// 定义触发时间
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).build();
// 将任务和Trigger放入scheduler
sched.scheduleJob(job, trigger);
sched.start();
}
在Nutz SetUp里面
@Override
public void destroy(NutConfig config) {
// TODO Auto-generated method stub
System.out.println("关闭服务");
//// //定时任务
// MainSchedule mainSchedule=new MainSchedule();
// mainSchedule.shutdownSchedule();
try {
config.getIoc().get(Scheduler.class).shutdown(true);
} catch (Exception e) {
}
}
用的是tomcat8.0.9,启动服务的时候正常,也能正常运行线程,但是在关闭服务的时候,线程无法关闭
控制台报错
Nutz.Mvc[nutz] is deposing ...
关闭服务
[DEBUG] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.NutIoc.get(NutIoc.java:149)
Get 'scheduler'<interface org.quartz.Scheduler>
[DEBUG] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.NutIoc.get(NutIoc.java:169)
>> Load definition
[INFO ] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:241)
Closing class org.nutz.ioc.impl.NutIoc@729029038 startup date [Fri Jul 15 10:33:57 CST 2016]
[DEBUG] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:91)
Depose object 'dao' ...
[DEBUG] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:91)
Depose object 'tmpFilePool' ...
[DEBUG] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:91)
Depose object 'conf' ...
[DEBUG] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:91)
Depose object 'dataSource' ...
[INFO ] 2016-07-15 10:34:10,388 method:com.alibaba.druid.pool.DruidDataSource.close(DruidDataSource.java:1436)
{dataSource-1} closed
[INFO ] 2016-07-15 10:34:10,388 method:org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:245)
class org.nutz.ioc.impl.NutIoc@729029038 is deposed.
[INFO ] 2016-07-15 10:34:10,388 method:org.nutz.mvc.impl.NutLoading.depose(NutLoading.java:434)
Nutz.Mvc[nutz] is down in 0ms
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
警告: The web application [/KMIA_ABCM] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
警告: The web application [/KMIA_ABCM] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-2] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-3] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-4] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-5] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-6] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-7] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-8] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-9] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_Worker-10] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:568)
七月 15, 2016 10:34:10 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
警告: The web application [/KMIA_ABCM] appears to have started a thread named [DefaultQuartzScheduler_QuartzSchedulerThread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:311)
七月 15, 2016 10:34:10 上午 org.apache.coyote.AbstractProtocol stop
信息: Stopping ProtocolHandler ["http-nio-8088"]
七月 15, 2016 10:34:10 上午 org.apache.coyote.AbstractProtocol stop
信息: Stopping ProtocolHandler ["ajp-nio-8009"]
七月 15, 2016 10:34:10 上午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["http-nio-8088"]
七月 15, 2016 10:34:10 上午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["ajp-nio-8009"]
请问是为什么会有11个线程?然后为什么会关不掉会有内存溢出?
谢谢了