欢迎来到天天文库
浏览记录
ID:37898054
大小:72.50 KB
页数:12页
时间:2019-06-02
《Spring中配置定时器详解》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、现在想要获得在特定时间或者指定时间执行相应功能有两种做法在applicationContext.xml中写入如下Bean 1000 2、ame="period"> 3600000 true 3、uler" class="org.springframework.scheduling.timer.TimerFactoryBean"> 4、ice"> 然后写SampleTask类,如下:packagecom.css.wam.portlet;importjava.util.ArrayList;importjava.util.Calendar;importjava.util.Iterator;importjava.util.List;importj5、ava.util.TimerTask;importjavax.servlet.ServletContext;字串2importorg.apache.jetspeed.security.SecurityException;字串9importcom.css.wam.service.WorkService;字串1@SuppressWarnings("unused")classSampleTaskextendsTimerTask{ 字串2 privatestaticfinalintC_SCHEDULE_HOU6、R=23;//设置指定时间 privateWorkServiceworkService; privateListusers; privateListteams; privateWorkPortletwork; publicvoidsetWorkService(WorkServiceworkService){ this.workService=workService;}字串7publicvoidsetWork(WorkPortletwork){ this.work=work;}字串47、 publicSampleTask(){ } @SuppressWarnings("unchecked")publicvoidrun(){ Calendarcal=Calendar.getInstance(); try{ users=work.getUsers(); teams=newArrayList(); for(Iteratorit=users.iterator();it.hasNext();) { 8、 Stringteamname=work.getGroupsByUser((String)it.next()); teams.add(teamname); } //查看当前时间与指定是否一致,一致则执行任务 if(C_SCHEDULE_HOUR==cal.get(Calendar.HOUR_OF_DAY))字串6
2、ame="period"> 3600000 true 3、uler" class="org.springframework.scheduling.timer.TimerFactoryBean"> 4、ice"> 然后写SampleTask类,如下:packagecom.css.wam.portlet;importjava.util.ArrayList;importjava.util.Calendar;importjava.util.Iterator;importjava.util.List;importj5、ava.util.TimerTask;importjavax.servlet.ServletContext;字串2importorg.apache.jetspeed.security.SecurityException;字串9importcom.css.wam.service.WorkService;字串1@SuppressWarnings("unused")classSampleTaskextendsTimerTask{ 字串2 privatestaticfinalintC_SCHEDULE_HOU6、R=23;//设置指定时间 privateWorkServiceworkService; privateListusers; privateListteams; privateWorkPortletwork; publicvoidsetWorkService(WorkServiceworkService){ this.workService=workService;}字串7publicvoidsetWork(WorkPortletwork){ this.work=work;}字串47、 publicSampleTask(){ } @SuppressWarnings("unchecked")publicvoidrun(){ Calendarcal=Calendar.getInstance(); try{ users=work.getUsers(); teams=newArrayList(); for(Iteratorit=users.iterator();it.hasNext();) { 8、 Stringteamname=work.getGroupsByUser((String)it.next()); teams.add(teamname); } //查看当前时间与指定是否一致,一致则执行任务 if(C_SCHEDULE_HOUR==cal.get(Calendar.HOUR_OF_DAY))字串6
3、uler" class="org.springframework.scheduling.timer.TimerFactoryBean"> 4、ice"> 然后写SampleTask类,如下:packagecom.css.wam.portlet;importjava.util.ArrayList;importjava.util.Calendar;importjava.util.Iterator;importjava.util.List;importj5、ava.util.TimerTask;importjavax.servlet.ServletContext;字串2importorg.apache.jetspeed.security.SecurityException;字串9importcom.css.wam.service.WorkService;字串1@SuppressWarnings("unused")classSampleTaskextendsTimerTask{ 字串2 privatestaticfinalintC_SCHEDULE_HOU6、R=23;//设置指定时间 privateWorkServiceworkService; privateListusers; privateListteams; privateWorkPortletwork; publicvoidsetWorkService(WorkServiceworkService){ this.workService=workService;}字串7publicvoidsetWork(WorkPortletwork){ this.work=work;}字串47、 publicSampleTask(){ } @SuppressWarnings("unchecked")publicvoidrun(){ Calendarcal=Calendar.getInstance(); try{ users=work.getUsers(); teams=newArrayList(); for(Iteratorit=users.iterator();it.hasNext();) { 8、 Stringteamname=work.getGroupsByUser((String)it.next()); teams.add(teamname); } //查看当前时间与指定是否一致,一致则执行任务 if(C_SCHEDULE_HOUR==cal.get(Calendar.HOUR_OF_DAY))字串6
4、ice"> 然后写SampleTask类,如下:packagecom.css.wam.portlet;importjava.util.ArrayList;importjava.util.Calendar;importjava.util.Iterator;importjava.util.List;importj
5、ava.util.TimerTask;importjavax.servlet.ServletContext;字串2importorg.apache.jetspeed.security.SecurityException;字串9importcom.css.wam.service.WorkService;字串1@SuppressWarnings("unused")classSampleTaskextendsTimerTask{ 字串2 privatestaticfinalintC_SCHEDULE_HOU
6、R=23;//设置指定时间 privateWorkServiceworkService; privateListusers; privateListteams; privateWorkPortletwork; publicvoidsetWorkService(WorkServiceworkService){ this.workService=workService;}字串7publicvoidsetWork(WorkPortletwork){ this.work=work;}字串4
7、 publicSampleTask(){ } @SuppressWarnings("unchecked")publicvoidrun(){ Calendarcal=Calendar.getInstance(); try{ users=work.getUsers(); teams=newArrayList(); for(Iteratorit=users.iterator();it.hasNext();) {
8、 Stringteamname=work.getGroupsByUser((String)it.next()); teams.add(teamname); } //查看当前时间与指定是否一致,一致则执行任务 if(C_SCHEDULE_HOUR==cal.get(Calendar.HOUR_OF_DAY))字串6
此文档下载收益归作者所有