Scheduled delivery of Java play Freamwork news notifications

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.