For an account management system, i need to send an email to the users in database which have XX days remaining for their subscription.
The idea is to create a function in my Java EE code (the application in written in Java/Java EE with VAADIN 7.2 framework) which checks remaining time of each users, and sends an email if the remaining time is XX days with my MailEngine() class;
The problem is that i don't know how to create a daemon like that in Java/Java EE, or call a function everyday at 12:00 PM for example.
The solution can be to create a Java App witch is called by crontab everyday but the best solution is to do it in my Java EE application, then it'll be fully customizable (change mail body/ title in the web interfaces, for admins who are not developers).
EDIT:
I tested this code sent by joseripla
import javax.ejb.Schedule;
import javax.ejb.Singleton;
@Singleton
public class MarketingMailEngine {
int count = 0;
//Print to log every 5 seconds
@Schedule(second="*/5", minute="*", hour="*", persistent=true)
public void print() {
System.out.println(count);
count++;
}
}
But it only prints 0, even if i wait for some minutes (it should do it every 5 secs).