当特定日期到达 java 或 vaadin 时显示通知

Display notification when specific date arrives in java or vaadin

我正在使用 vaadin 框架来构建我的项目,我想在特定日期显示通知,我有一个 return 这个日期的功能,我想知道如何显示当系统日期达到此计算日期时的消息。

//I'd like to display a notification when the system's date reaches this "date_main_levee"
public Date getMainLevee(Date date_ouverture_plis, int duree_caution){
    Date date_main_levee;
    Calendar c = Calendar.getInstance();
    c.setTime(date_ouverture_plis);
    c.add(Calendar.DATE, duree_caution);
    date_main_levee=c.getTime();

    return date_main_levee;
}

基本上我正在寻找的是 Android 中这个简单的解决方案:http://blog.blundell-apps.com/notification-for-a-user-chosen-time/

在 vaadin 中是否对此有任何建议(java 解决方案也会有所帮助,因为 vaadin 是一个 java 框架)。

编辑

我的问题不是通知本身,而是运行和测试实际日期是否等于我提供的日期参数的服务

编辑 2:

我使用此代码,它在控制台中显示结果,但 UI 中没有通知:

这是我有一个简单按钮的视图,当我单击它时任务应该开始:

final Button annulerLC=new Button("Annuler");
annulerLC.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            // TODO Auto-generated method stub
            DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            try {
                date = dateFormatter.parse("2015-04-23 18:29:00");
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            Timer timer = new Timer();

            timer.schedule(new CautionTask(), date);
        }
    });

TimerTask 在这个单独的 class 中定义(它只显示一个通知):

   public class CautionTask extends TimerTask{

public void run()
{
    Notification.show("success");//Doesn't show anything
    System.out.println("success+++");//Works fine
}

}

我在控制台上得到:success+++ 所以 system.out.println 显示了确切的结果,但是视图不显示通知 "success"。

谢谢。

当您需要 "realtime" 通知时,在您的应用程序 init() 方法中启动后台线程,然后根据需要显示通知。 当然你必须使用 some push system,所以通知被推送到客户端。另请阅读有关从另一个线程访问 UI 的部分。

当您不需要实时通知时,只需将检查代码添加到您的某些UI 表单中,然后将其显示在那里。在这种情况下不需要后台服务。

你需要:

a) Server push 所以后台服务器线程中的变化被推送到客户端。

b) Correct access to the UI 来自后台 thread/task,因为它可能在另一个上下文中运行