Package com.wanhua.thread;
Scheduled Send task thread
Import java.util.List;
Import Java.util.TimerTask;
Import Play.db.jpa.JPAPlugin;
Import controllers. News;
Import models. Childrennew;
Import models. Log;
Import models. New;
public class Sendnewstask extends TimerTask {
Select the sent sub-news
Private list<childrennew> childrennews;
Send Time
Private String Issuestime;
Author
Private String author;
/**
* Constructor function
*
* @param childrennews
*/
Public Sendnewstask (string author, String issuestime, list<childrennew> childrennews) {
This.author = author;
This.issuestime = Issuestime;
This.childrennews = Childrennews;
}
@Override
public void Run () {
Select the sent sub-news
list<childrennew> childrennews = this.childrennews;
String issuestime = this.issuestime;
String author = this.author;
Add JPA Environment
Jpaplugin.starttx (FALSE);
Send a news task
New.sendnewstask (author, Issuestime, childrennews);
Jpaplugin.closetx (FALSE);
}
}
Timed task thread calls to implement timed news notifications
Timestamp publishtime = Prefutil.fortimestamp (issuestime);
Timed to send at some point
Date senddate = publishtime;
Timer timer = new timer ();
try {
Regularly send news notifications
Timer.schedule (New Sendnewstask (author, Issuestime, childrennews), senddate); Run after a specific time
} catch (Exception e) {
The timer and TimerTask are separate two objects, and when the TimerTask is scheduled using the schedule () method of the timer,
You must wait for the timer's cancel () execution to leave the TimerTask with the timer.
Timer.cancel ();
}
Scheduled delivery of Java play Freamwork news notifications