简体   繁体   中英

Java Scheduling task

I am developing a spring mvc project where a notification will send to user mobile.User will select a datetime at format 'yyyy-MM-dd HH:mm' from frontend and save it to the database.when system time reach that time a notification will be send to the user mobile .

I created scheduler like this

  @Component
  public class NotificationScheduler extends BaseService {


  @Scheduled(fixedRate = 300000)
  public void sendNotification() {

    Date currentDate = new Date();

    System.err.println("HHHHHHHHHKKKKKK");

    List<ImageInfo> listImageInfo = imageInfoDao.getImageOfParticularDate(currentDate);

 }
}

this is my dao function which run a wuery to database

  public List getImageOfParticularDate(Date date) {
    session = getSession();
    session.beginTransaction();
    List<ImageInfo> imageInfoList = session.createQuery("select img from ImageInfo img where img.publishedTime =:publishedTime  ").setParameter("publishedTime", date).list();
    session.getTransaction().commit();
    return imageInfoList;
}

this code is checking repeatedly at 5 min interval whether system time equal to publish time.if it is equal then a notification will be sent.I used Date type in model and Date type column in database. I want to know my approach is right or wrong because i can not get desire output.

Why don't you use a debug mode? Change, your the time rate you use in order to not wait too much, but I think you could determine that yourself, could you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM