You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "Leonardo K. Shikida" <sh...@gmail.com> on 2013/12/28 19:53:39 UTC
doubt about timer service
Hi
I'd like to start a calendar scheduled job for 1 minute from now.
I was trying to assemble a cron expression like this, but instead, it's
generating
a lot of jobs (really)
looks like something really stupid
The code is as simple as this
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
@Singleton
@Startup
public class TimerEJB {
@Resource
private TimerService timerService;
@Timeout
public void executeTimer(Timer timer) {
System.out.println(timer);
}
private String toString(ScheduleExpression schedule) {
return "MyScheduleExpression [getDayOfMonth()=" +
schedule.getDayOfMonth()
+ ", getDayOfWeek()=" + schedule.getDayOfWeek()
+ ", getEnd()=" + schedule.getEnd()
+ ", getHour()=" + schedule.getHour()
+ ", getMinute()=" + schedule.getMinute()
+ ", getMonth()=" + schedule.getMonth()
+ ", getSecond()=" + schedule.getSecond()
+ ", getStart()=" + schedule.getStart()
+ ", getYear()=" + schedule.getYear()
+ ", getTimezone()=" + schedule.getTimezone() + "]";
}
@PostConstruct
public void create() {
Calendar future = new GregorianCalendar();
future.setTimeInMillis(System.currentTimeMillis() + 60000);
int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
String dayOfWeekName = null;
switch (dayOfWeek) {
case Calendar.MONDAY:
dayOfWeekName = "Mon";
break;
case Calendar.TUESDAY:
dayOfWeekName = "Tue";
break;
case Calendar.WEDNESDAY:
dayOfWeekName = "Wed";
break;
case Calendar.THURSDAY:
dayOfWeekName = "Thu";
break;
case Calendar.FRIDAY:
dayOfWeekName = "Fri";
break;
case Calendar.SATURDAY:
dayOfWeekName = "Sat";
break;
case Calendar.SUNDAY:
dayOfWeekName = "Sun";
break;
}
String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s %6$s %7$s",
future.get(Calendar.SECOND),
future.get(Calendar.MINUTE),
future.get(Calendar.HOUR_OF_DAY),
dayOfWeekName,
future.get(Calendar.DAY_OF_MONTH),
future.get(Calendar.MONTH) + 1,
future.get(Calendar.YEAR));
String[] cron = cronExp.split(" ");
String[] ss = new String[7];
for (int i = 0; i < cron.length; i++) {
ss[i] = cron[i];
}
ScheduleExpression exp = new ScheduleExpression();
exp.second(0);
exp.minute(ss[1]);
exp.hour(ss[2]);
exp.dayOfWeek(ss[3]);
exp.dayOfMonth(ss[4]);
exp.month(ss[5]);
exp.year(ss[6]);
System.out.println(toString(exp));
Timer t = this.timerService.createCalendarTimer(exp);
System.out.println("Created "+t);
}
}
output for this looks like this
MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12, getSecond()=0,
getStart()=null, getYear()=2013, getTimezone()=null]
Created org.apache.openejb.core.timer.TimerImpl@298a0c11
an after some seconds
org.apache.openejb.core.timer.TimerImpl@5f1e961a
org.apache.openejb.core.timer.TimerImpl@5f1e961a
org.apache.openejb.core.timer.TimerImpl@5f1e961a
org.apache.openejb.core.timer.TimerImpl@5f1e961a
org.apache.openejb.core.timer.TimerImpl@5f1e961a
org.apache.openejb.core.timer.TimerImpl@5f1e961a
org.apache.openejb.core.timer.TimerImpl@5f1e961a...
any help is welcome
TIA
Leo
Re: doubt about timer service
Posted by "Leonardo K. Shikida" <sh...@gmail.com>.
If I set start to be the same time as specified by the calendar expression,
I get
org.quartz.SchedulerException: Based on configured schedule, the given
trigger
'OPEN_EJB_TIMEOUT_TRIGGER_GROUP.OPEN_EJB_TIMEOUT_TRIGGER_TimerEJB_1' will
never fire.
but if I just set only the end to be the same date, it seems to do the
trick.
thanks :-)
[]
Leo
On Sun, Dec 29, 2013 at 10:08 AM, Radhakrishna Kalyan
<nr...@gmail.com>wrote:
> Sorry, I misunderstood.
>
> You can use timerService.createSingleActionTimer(...). This will execute
> only once and then you don't create more timers in your @Timeout method.
>
>
> On Sun, Dec 29, 2013 at 12:40 PM, Leonardo K. Shikida <shikida@gmail.com
> >wrote:
>
> > Hi Kalyan
> >
> > I don' t want to run it every minute (for this, I could use * as minute)
> >
> > I want to run it in a specific date and time, and only once.
> >
> > TIA
> >
> > Leo
> >
> > []
> >
> > Leo
> >
> >
> > On Sat, Dec 28, 2013 at 11:28 PM, Nrkkalyan <nr...@gmail.com> wrote:
> >
> > > If you mean you would like your timer service to run every min 24/7
> then
> > > you
> > > You need only the following. exp.minutes("*/1").hour("*")
> > >
> > > Hope I am clearly understanding your need.
> > >
> > > Regards
> > > /Kalyan
> > > 0733312584
> > >
> > > PS: May have typos due to using mobile
> > >
> > > On 28 dec 2013, at 19:53, "Leonardo K. Shikida" <sh...@gmail.com>
> > wrote:
> > >
> > > > Hi
> > > >
> > > > I'd like to start a calendar scheduled job for 1 minute from now.
> > > >
> > > > I was trying to assemble a cron expression like this, but instead,
> it's
> > > > generating
> > > > a lot of jobs (really)
> > > >
> > > > looks like something really stupid
> > > >
> > > > The code is as simple as this
> > > >
> > > > import java.util.Calendar;
> > > > import java.util.GregorianCalendar;
> > > >
> > > > import javax.annotation.PostConstruct;
> > > > import javax.annotation.Resource;
> > > > import javax.ejb.ScheduleExpression;
> > > > import javax.ejb.Singleton;
> > > > import javax.ejb.Startup;
> > > > import javax.ejb.Timeout;
> > > > import javax.ejb.Timer;
> > > > import javax.ejb.TimerService;
> > > >
> > > > @Singleton
> > > > @Startup
> > > > public class TimerEJB {
> > > >
> > > > @Resource
> > > > private TimerService timerService;
> > > >
> > > > @Timeout
> > > > public void executeTimer(Timer timer) {
> > > > System.out.println(timer);
> > > > }
> > > >
> > > > private String toString(ScheduleExpression schedule) {
> > > > return "MyScheduleExpression [getDayOfMonth()=" +
> > > > schedule.getDayOfMonth()
> > > > + ", getDayOfWeek()=" + schedule.getDayOfWeek()
> > > > + ", getEnd()=" + schedule.getEnd()
> > > > + ", getHour()=" + schedule.getHour()
> > > > + ", getMinute()=" + schedule.getMinute()
> > > > + ", getMonth()=" + schedule.getMonth()
> > > > + ", getSecond()=" + schedule.getSecond()
> > > > + ", getStart()=" + schedule.getStart()
> > > > + ", getYear()=" + schedule.getYear()
> > > > + ", getTimezone()=" + schedule.getTimezone() + "]";
> > > > }
> > > >
> > > > @PostConstruct
> > > > public void create() {
> > > >
> > > > Calendar future = new GregorianCalendar();
> > > > future.setTimeInMillis(System.currentTimeMillis() + 60000);
> > > >
> > > > int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
> > > > String dayOfWeekName = null;
> > > >
> > > > switch (dayOfWeek) {
> > > > case Calendar.MONDAY:
> > > > dayOfWeekName = "Mon";
> > > > break;
> > > > case Calendar.TUESDAY:
> > > > dayOfWeekName = "Tue";
> > > > break;
> > > > case Calendar.WEDNESDAY:
> > > > dayOfWeekName = "Wed";
> > > > break;
> > > > case Calendar.THURSDAY:
> > > > dayOfWeekName = "Thu";
> > > > break;
> > > > case Calendar.FRIDAY:
> > > > dayOfWeekName = "Fri";
> > > > break;
> > > > case Calendar.SATURDAY:
> > > > dayOfWeekName = "Sat";
> > > > break;
> > > > case Calendar.SUNDAY:
> > > > dayOfWeekName = "Sun";
> > > > break;
> > > > }
> > > >
> > > > String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s %6$s
> > > %7$s",
> > > > future.get(Calendar.SECOND),
> > > > future.get(Calendar.MINUTE),
> > > > future.get(Calendar.HOUR_OF_DAY),
> > > > dayOfWeekName,
> > > > future.get(Calendar.DAY_OF_MONTH),
> > > > future.get(Calendar.MONTH) + 1,
> > > > future.get(Calendar.YEAR));
> > > >
> > > > String[] cron = cronExp.split(" ");
> > > > String[] ss = new String[7];
> > > > for (int i = 0; i < cron.length; i++) {
> > > > ss[i] = cron[i];
> > > > }
> > > >
> > > > ScheduleExpression exp = new ScheduleExpression();
> > > > exp.second(0);
> > > > exp.minute(ss[1]);
> > > > exp.hour(ss[2]);
> > > > exp.dayOfWeek(ss[3]);
> > > > exp.dayOfMonth(ss[4]);
> > > > exp.month(ss[5]);
> > > > exp.year(ss[6]);
> > > >
> > > > System.out.println(toString(exp));
> > > >
> > > > Timer t = this.timerService.createCalendarTimer(exp);
> > > >
> > > > System.out.println("Created "+t);
> > > > }
> > > >
> > > > }
> > > >
> > > > output for this looks like this
> > > >
> > > > MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
> > > > getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12,
> > > getSecond()=0,
> > > > getStart()=null, getYear()=2013, getTimezone()=null]
> > > >
> > > > Created org.apache.openejb.core.timer.TimerImpl@298a0c11
> > > >
> > > > an after some seconds
> > > >
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a...
> > > >
> > > > any help is welcome
> > > >
> > > > TIA
> > > >
> > > > Leo
> > >
> >
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P: +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>
Re: doubt about timer service
Posted by Radhakrishna Kalyan <nr...@gmail.com>.
I have not tested it but try using exp.start(date).end(<date after 1 min).
Hope this will work. If not then let me know.
On Sun, Dec 29, 2013 at 1:17 PM, Leonardo K. Shikida <sh...@gmail.com>wrote:
> Yes, I can.
>
> I just would like to know how I could do the same using a calendar
> expression
>
> []
>
> Leo
>
>
> On Sun, Dec 29, 2013 at 10:08 AM, Radhakrishna Kalyan
> <nr...@gmail.com>wrote:
>
> > Sorry, I misunderstood.
> >
> > You can use timerService.createSingleActionTimer(...). This will execute
> > only once and then you don't create more timers in your @Timeout method.
> >
> >
> > On Sun, Dec 29, 2013 at 12:40 PM, Leonardo K. Shikida <shikida@gmail.com
> > >wrote:
> >
> > > Hi Kalyan
> > >
> > > I don' t want to run it every minute (for this, I could use * as
> minute)
> > >
> > > I want to run it in a specific date and time, and only once.
> > >
> > > TIA
> > >
> > > Leo
> > >
> > > []
> > >
> > > Leo
> > >
> > >
> > > On Sat, Dec 28, 2013 at 11:28 PM, Nrkkalyan <nr...@gmail.com>
> wrote:
> > >
> > > > If you mean you would like your timer service to run every min 24/7
> > then
> > > > you
> > > > You need only the following. exp.minutes("*/1").hour("*")
> > > >
> > > > Hope I am clearly understanding your need.
> > > >
> > > > Regards
> > > > /Kalyan
> > > > 0733312584
> > > >
> > > > PS: May have typos due to using mobile
> > > >
> > > > On 28 dec 2013, at 19:53, "Leonardo K. Shikida" <sh...@gmail.com>
> > > wrote:
> > > >
> > > > > Hi
> > > > >
> > > > > I'd like to start a calendar scheduled job for 1 minute from now.
> > > > >
> > > > > I was trying to assemble a cron expression like this, but instead,
> > it's
> > > > > generating
> > > > > a lot of jobs (really)
> > > > >
> > > > > looks like something really stupid
> > > > >
> > > > > The code is as simple as this
> > > > >
> > > > > import java.util.Calendar;
> > > > > import java.util.GregorianCalendar;
> > > > >
> > > > > import javax.annotation.PostConstruct;
> > > > > import javax.annotation.Resource;
> > > > > import javax.ejb.ScheduleExpression;
> > > > > import javax.ejb.Singleton;
> > > > > import javax.ejb.Startup;
> > > > > import javax.ejb.Timeout;
> > > > > import javax.ejb.Timer;
> > > > > import javax.ejb.TimerService;
> > > > >
> > > > > @Singleton
> > > > > @Startup
> > > > > public class TimerEJB {
> > > > >
> > > > > @Resource
> > > > > private TimerService timerService;
> > > > >
> > > > > @Timeout
> > > > > public void executeTimer(Timer timer) {
> > > > > System.out.println(timer);
> > > > > }
> > > > >
> > > > > private String toString(ScheduleExpression schedule) {
> > > > > return "MyScheduleExpression [getDayOfMonth()=" +
> > > > > schedule.getDayOfMonth()
> > > > > + ", getDayOfWeek()=" + schedule.getDayOfWeek()
> > > > > + ", getEnd()=" + schedule.getEnd()
> > > > > + ", getHour()=" + schedule.getHour()
> > > > > + ", getMinute()=" + schedule.getMinute()
> > > > > + ", getMonth()=" + schedule.getMonth()
> > > > > + ", getSecond()=" + schedule.getSecond()
> > > > > + ", getStart()=" + schedule.getStart()
> > > > > + ", getYear()=" + schedule.getYear()
> > > > > + ", getTimezone()=" + schedule.getTimezone() + "]";
> > > > > }
> > > > >
> > > > > @PostConstruct
> > > > > public void create() {
> > > > >
> > > > > Calendar future = new GregorianCalendar();
> > > > > future.setTimeInMillis(System.currentTimeMillis() + 60000);
> > > > >
> > > > > int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
> > > > > String dayOfWeekName = null;
> > > > >
> > > > > switch (dayOfWeek) {
> > > > > case Calendar.MONDAY:
> > > > > dayOfWeekName = "Mon";
> > > > > break;
> > > > > case Calendar.TUESDAY:
> > > > > dayOfWeekName = "Tue";
> > > > > break;
> > > > > case Calendar.WEDNESDAY:
> > > > > dayOfWeekName = "Wed";
> > > > > break;
> > > > > case Calendar.THURSDAY:
> > > > > dayOfWeekName = "Thu";
> > > > > break;
> > > > > case Calendar.FRIDAY:
> > > > > dayOfWeekName = "Fri";
> > > > > break;
> > > > > case Calendar.SATURDAY:
> > > > > dayOfWeekName = "Sat";
> > > > > break;
> > > > > case Calendar.SUNDAY:
> > > > > dayOfWeekName = "Sun";
> > > > > break;
> > > > > }
> > > > >
> > > > > String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s
> %6$s
> > > > %7$s",
> > > > > future.get(Calendar.SECOND),
> > > > > future.get(Calendar.MINUTE),
> > > > > future.get(Calendar.HOUR_OF_DAY),
> > > > > dayOfWeekName,
> > > > > future.get(Calendar.DAY_OF_MONTH),
> > > > > future.get(Calendar.MONTH) + 1,
> > > > > future.get(Calendar.YEAR));
> > > > >
> > > > > String[] cron = cronExp.split(" ");
> > > > > String[] ss = new String[7];
> > > > > for (int i = 0; i < cron.length; i++) {
> > > > > ss[i] = cron[i];
> > > > > }
> > > > >
> > > > > ScheduleExpression exp = new ScheduleExpression();
> > > > > exp.second(0);
> > > > > exp.minute(ss[1]);
> > > > > exp.hour(ss[2]);
> > > > > exp.dayOfWeek(ss[3]);
> > > > > exp.dayOfMonth(ss[4]);
> > > > > exp.month(ss[5]);
> > > > > exp.year(ss[6]);
> > > > >
> > > > > System.out.println(toString(exp));
> > > > >
> > > > > Timer t = this.timerService.createCalendarTimer(exp);
> > > > >
> > > > > System.out.println("Created "+t);
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > > output for this looks like this
> > > > >
> > > > > MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
> > > > > getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12,
> > > > getSecond()=0,
> > > > > getStart()=null, getYear()=2013, getTimezone()=null]
> > > > >
> > > > > Created org.apache.openejb.core.timer.TimerImpl@298a0c11
> > > > >
> > > > > an after some seconds
> > > > >
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a...
> > > > >
> > > > > any help is welcome
> > > > >
> > > > > TIA
> > > > >
> > > > > Leo
> > > >
> > >
> >
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P: +46 733 312 584
> > http://about.me/nrkkalyan
> > <http://about.me/nrkkalyan>
> >
>
--
Thanks and Regards
N Radhakrishna Kalyan
P: +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>
Re: doubt about timer service
Posted by "Leonardo K. Shikida" <sh...@gmail.com>.
Yes, I can.
I just would like to know how I could do the same using a calendar
expression
[]
Leo
On Sun, Dec 29, 2013 at 10:08 AM, Radhakrishna Kalyan
<nr...@gmail.com>wrote:
> Sorry, I misunderstood.
>
> You can use timerService.createSingleActionTimer(...). This will execute
> only once and then you don't create more timers in your @Timeout method.
>
>
> On Sun, Dec 29, 2013 at 12:40 PM, Leonardo K. Shikida <shikida@gmail.com
> >wrote:
>
> > Hi Kalyan
> >
> > I don' t want to run it every minute (for this, I could use * as minute)
> >
> > I want to run it in a specific date and time, and only once.
> >
> > TIA
> >
> > Leo
> >
> > []
> >
> > Leo
> >
> >
> > On Sat, Dec 28, 2013 at 11:28 PM, Nrkkalyan <nr...@gmail.com> wrote:
> >
> > > If you mean you would like your timer service to run every min 24/7
> then
> > > you
> > > You need only the following. exp.minutes("*/1").hour("*")
> > >
> > > Hope I am clearly understanding your need.
> > >
> > > Regards
> > > /Kalyan
> > > 0733312584
> > >
> > > PS: May have typos due to using mobile
> > >
> > > On 28 dec 2013, at 19:53, "Leonardo K. Shikida" <sh...@gmail.com>
> > wrote:
> > >
> > > > Hi
> > > >
> > > > I'd like to start a calendar scheduled job for 1 minute from now.
> > > >
> > > > I was trying to assemble a cron expression like this, but instead,
> it's
> > > > generating
> > > > a lot of jobs (really)
> > > >
> > > > looks like something really stupid
> > > >
> > > > The code is as simple as this
> > > >
> > > > import java.util.Calendar;
> > > > import java.util.GregorianCalendar;
> > > >
> > > > import javax.annotation.PostConstruct;
> > > > import javax.annotation.Resource;
> > > > import javax.ejb.ScheduleExpression;
> > > > import javax.ejb.Singleton;
> > > > import javax.ejb.Startup;
> > > > import javax.ejb.Timeout;
> > > > import javax.ejb.Timer;
> > > > import javax.ejb.TimerService;
> > > >
> > > > @Singleton
> > > > @Startup
> > > > public class TimerEJB {
> > > >
> > > > @Resource
> > > > private TimerService timerService;
> > > >
> > > > @Timeout
> > > > public void executeTimer(Timer timer) {
> > > > System.out.println(timer);
> > > > }
> > > >
> > > > private String toString(ScheduleExpression schedule) {
> > > > return "MyScheduleExpression [getDayOfMonth()=" +
> > > > schedule.getDayOfMonth()
> > > > + ", getDayOfWeek()=" + schedule.getDayOfWeek()
> > > > + ", getEnd()=" + schedule.getEnd()
> > > > + ", getHour()=" + schedule.getHour()
> > > > + ", getMinute()=" + schedule.getMinute()
> > > > + ", getMonth()=" + schedule.getMonth()
> > > > + ", getSecond()=" + schedule.getSecond()
> > > > + ", getStart()=" + schedule.getStart()
> > > > + ", getYear()=" + schedule.getYear()
> > > > + ", getTimezone()=" + schedule.getTimezone() + "]";
> > > > }
> > > >
> > > > @PostConstruct
> > > > public void create() {
> > > >
> > > > Calendar future = new GregorianCalendar();
> > > > future.setTimeInMillis(System.currentTimeMillis() + 60000);
> > > >
> > > > int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
> > > > String dayOfWeekName = null;
> > > >
> > > > switch (dayOfWeek) {
> > > > case Calendar.MONDAY:
> > > > dayOfWeekName = "Mon";
> > > > break;
> > > > case Calendar.TUESDAY:
> > > > dayOfWeekName = "Tue";
> > > > break;
> > > > case Calendar.WEDNESDAY:
> > > > dayOfWeekName = "Wed";
> > > > break;
> > > > case Calendar.THURSDAY:
> > > > dayOfWeekName = "Thu";
> > > > break;
> > > > case Calendar.FRIDAY:
> > > > dayOfWeekName = "Fri";
> > > > break;
> > > > case Calendar.SATURDAY:
> > > > dayOfWeekName = "Sat";
> > > > break;
> > > > case Calendar.SUNDAY:
> > > > dayOfWeekName = "Sun";
> > > > break;
> > > > }
> > > >
> > > > String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s %6$s
> > > %7$s",
> > > > future.get(Calendar.SECOND),
> > > > future.get(Calendar.MINUTE),
> > > > future.get(Calendar.HOUR_OF_DAY),
> > > > dayOfWeekName,
> > > > future.get(Calendar.DAY_OF_MONTH),
> > > > future.get(Calendar.MONTH) + 1,
> > > > future.get(Calendar.YEAR));
> > > >
> > > > String[] cron = cronExp.split(" ");
> > > > String[] ss = new String[7];
> > > > for (int i = 0; i < cron.length; i++) {
> > > > ss[i] = cron[i];
> > > > }
> > > >
> > > > ScheduleExpression exp = new ScheduleExpression();
> > > > exp.second(0);
> > > > exp.minute(ss[1]);
> > > > exp.hour(ss[2]);
> > > > exp.dayOfWeek(ss[3]);
> > > > exp.dayOfMonth(ss[4]);
> > > > exp.month(ss[5]);
> > > > exp.year(ss[6]);
> > > >
> > > > System.out.println(toString(exp));
> > > >
> > > > Timer t = this.timerService.createCalendarTimer(exp);
> > > >
> > > > System.out.println("Created "+t);
> > > > }
> > > >
> > > > }
> > > >
> > > > output for this looks like this
> > > >
> > > > MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
> > > > getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12,
> > > getSecond()=0,
> > > > getStart()=null, getYear()=2013, getTimezone()=null]
> > > >
> > > > Created org.apache.openejb.core.timer.TimerImpl@298a0c11
> > > >
> > > > an after some seconds
> > > >
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > > org.apache.openejb.core.timer.TimerImpl@5f1e961a...
> > > >
> > > > any help is welcome
> > > >
> > > > TIA
> > > >
> > > > Leo
> > >
> >
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P: +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>
Re: doubt about timer service
Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Sorry, I misunderstood.
You can use timerService.createSingleActionTimer(...). This will execute
only once and then you don't create more timers in your @Timeout method.
On Sun, Dec 29, 2013 at 12:40 PM, Leonardo K. Shikida <sh...@gmail.com>wrote:
> Hi Kalyan
>
> I don' t want to run it every minute (for this, I could use * as minute)
>
> I want to run it in a specific date and time, and only once.
>
> TIA
>
> Leo
>
> []
>
> Leo
>
>
> On Sat, Dec 28, 2013 at 11:28 PM, Nrkkalyan <nr...@gmail.com> wrote:
>
> > If you mean you would like your timer service to run every min 24/7 then
> > you
> > You need only the following. exp.minutes("*/1").hour("*")
> >
> > Hope I am clearly understanding your need.
> >
> > Regards
> > /Kalyan
> > 0733312584
> >
> > PS: May have typos due to using mobile
> >
> > On 28 dec 2013, at 19:53, "Leonardo K. Shikida" <sh...@gmail.com>
> wrote:
> >
> > > Hi
> > >
> > > I'd like to start a calendar scheduled job for 1 minute from now.
> > >
> > > I was trying to assemble a cron expression like this, but instead, it's
> > > generating
> > > a lot of jobs (really)
> > >
> > > looks like something really stupid
> > >
> > > The code is as simple as this
> > >
> > > import java.util.Calendar;
> > > import java.util.GregorianCalendar;
> > >
> > > import javax.annotation.PostConstruct;
> > > import javax.annotation.Resource;
> > > import javax.ejb.ScheduleExpression;
> > > import javax.ejb.Singleton;
> > > import javax.ejb.Startup;
> > > import javax.ejb.Timeout;
> > > import javax.ejb.Timer;
> > > import javax.ejb.TimerService;
> > >
> > > @Singleton
> > > @Startup
> > > public class TimerEJB {
> > >
> > > @Resource
> > > private TimerService timerService;
> > >
> > > @Timeout
> > > public void executeTimer(Timer timer) {
> > > System.out.println(timer);
> > > }
> > >
> > > private String toString(ScheduleExpression schedule) {
> > > return "MyScheduleExpression [getDayOfMonth()=" +
> > > schedule.getDayOfMonth()
> > > + ", getDayOfWeek()=" + schedule.getDayOfWeek()
> > > + ", getEnd()=" + schedule.getEnd()
> > > + ", getHour()=" + schedule.getHour()
> > > + ", getMinute()=" + schedule.getMinute()
> > > + ", getMonth()=" + schedule.getMonth()
> > > + ", getSecond()=" + schedule.getSecond()
> > > + ", getStart()=" + schedule.getStart()
> > > + ", getYear()=" + schedule.getYear()
> > > + ", getTimezone()=" + schedule.getTimezone() + "]";
> > > }
> > >
> > > @PostConstruct
> > > public void create() {
> > >
> > > Calendar future = new GregorianCalendar();
> > > future.setTimeInMillis(System.currentTimeMillis() + 60000);
> > >
> > > int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
> > > String dayOfWeekName = null;
> > >
> > > switch (dayOfWeek) {
> > > case Calendar.MONDAY:
> > > dayOfWeekName = "Mon";
> > > break;
> > > case Calendar.TUESDAY:
> > > dayOfWeekName = "Tue";
> > > break;
> > > case Calendar.WEDNESDAY:
> > > dayOfWeekName = "Wed";
> > > break;
> > > case Calendar.THURSDAY:
> > > dayOfWeekName = "Thu";
> > > break;
> > > case Calendar.FRIDAY:
> > > dayOfWeekName = "Fri";
> > > break;
> > > case Calendar.SATURDAY:
> > > dayOfWeekName = "Sat";
> > > break;
> > > case Calendar.SUNDAY:
> > > dayOfWeekName = "Sun";
> > > break;
> > > }
> > >
> > > String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s %6$s
> > %7$s",
> > > future.get(Calendar.SECOND),
> > > future.get(Calendar.MINUTE),
> > > future.get(Calendar.HOUR_OF_DAY),
> > > dayOfWeekName,
> > > future.get(Calendar.DAY_OF_MONTH),
> > > future.get(Calendar.MONTH) + 1,
> > > future.get(Calendar.YEAR));
> > >
> > > String[] cron = cronExp.split(" ");
> > > String[] ss = new String[7];
> > > for (int i = 0; i < cron.length; i++) {
> > > ss[i] = cron[i];
> > > }
> > >
> > > ScheduleExpression exp = new ScheduleExpression();
> > > exp.second(0);
> > > exp.minute(ss[1]);
> > > exp.hour(ss[2]);
> > > exp.dayOfWeek(ss[3]);
> > > exp.dayOfMonth(ss[4]);
> > > exp.month(ss[5]);
> > > exp.year(ss[6]);
> > >
> > > System.out.println(toString(exp));
> > >
> > > Timer t = this.timerService.createCalendarTimer(exp);
> > >
> > > System.out.println("Created "+t);
> > > }
> > >
> > > }
> > >
> > > output for this looks like this
> > >
> > > MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
> > > getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12,
> > getSecond()=0,
> > > getStart()=null, getYear()=2013, getTimezone()=null]
> > >
> > > Created org.apache.openejb.core.timer.TimerImpl@298a0c11
> > >
> > > an after some seconds
> > >
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > > org.apache.openejb.core.timer.TimerImpl@5f1e961a...
> > >
> > > any help is welcome
> > >
> > > TIA
> > >
> > > Leo
> >
>
--
Thanks and Regards
N Radhakrishna Kalyan
P: +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>
Re: doubt about timer service
Posted by "Leonardo K. Shikida" <sh...@gmail.com>.
Hi Kalyan
I don' t want to run it every minute (for this, I could use * as minute)
I want to run it in a specific date and time, and only once.
TIA
Leo
[]
Leo
On Sat, Dec 28, 2013 at 11:28 PM, Nrkkalyan <nr...@gmail.com> wrote:
> If you mean you would like your timer service to run every min 24/7 then
> you
> You need only the following. exp.minutes("*/1").hour("*")
>
> Hope I am clearly understanding your need.
>
> Regards
> /Kalyan
> 0733312584
>
> PS: May have typos due to using mobile
>
> On 28 dec 2013, at 19:53, "Leonardo K. Shikida" <sh...@gmail.com> wrote:
>
> > Hi
> >
> > I'd like to start a calendar scheduled job for 1 minute from now.
> >
> > I was trying to assemble a cron expression like this, but instead, it's
> > generating
> > a lot of jobs (really)
> >
> > looks like something really stupid
> >
> > The code is as simple as this
> >
> > import java.util.Calendar;
> > import java.util.GregorianCalendar;
> >
> > import javax.annotation.PostConstruct;
> > import javax.annotation.Resource;
> > import javax.ejb.ScheduleExpression;
> > import javax.ejb.Singleton;
> > import javax.ejb.Startup;
> > import javax.ejb.Timeout;
> > import javax.ejb.Timer;
> > import javax.ejb.TimerService;
> >
> > @Singleton
> > @Startup
> > public class TimerEJB {
> >
> > @Resource
> > private TimerService timerService;
> >
> > @Timeout
> > public void executeTimer(Timer timer) {
> > System.out.println(timer);
> > }
> >
> > private String toString(ScheduleExpression schedule) {
> > return "MyScheduleExpression [getDayOfMonth()=" +
> > schedule.getDayOfMonth()
> > + ", getDayOfWeek()=" + schedule.getDayOfWeek()
> > + ", getEnd()=" + schedule.getEnd()
> > + ", getHour()=" + schedule.getHour()
> > + ", getMinute()=" + schedule.getMinute()
> > + ", getMonth()=" + schedule.getMonth()
> > + ", getSecond()=" + schedule.getSecond()
> > + ", getStart()=" + schedule.getStart()
> > + ", getYear()=" + schedule.getYear()
> > + ", getTimezone()=" + schedule.getTimezone() + "]";
> > }
> >
> > @PostConstruct
> > public void create() {
> >
> > Calendar future = new GregorianCalendar();
> > future.setTimeInMillis(System.currentTimeMillis() + 60000);
> >
> > int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
> > String dayOfWeekName = null;
> >
> > switch (dayOfWeek) {
> > case Calendar.MONDAY:
> > dayOfWeekName = "Mon";
> > break;
> > case Calendar.TUESDAY:
> > dayOfWeekName = "Tue";
> > break;
> > case Calendar.WEDNESDAY:
> > dayOfWeekName = "Wed";
> > break;
> > case Calendar.THURSDAY:
> > dayOfWeekName = "Thu";
> > break;
> > case Calendar.FRIDAY:
> > dayOfWeekName = "Fri";
> > break;
> > case Calendar.SATURDAY:
> > dayOfWeekName = "Sat";
> > break;
> > case Calendar.SUNDAY:
> > dayOfWeekName = "Sun";
> > break;
> > }
> >
> > String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s %6$s
> %7$s",
> > future.get(Calendar.SECOND),
> > future.get(Calendar.MINUTE),
> > future.get(Calendar.HOUR_OF_DAY),
> > dayOfWeekName,
> > future.get(Calendar.DAY_OF_MONTH),
> > future.get(Calendar.MONTH) + 1,
> > future.get(Calendar.YEAR));
> >
> > String[] cron = cronExp.split(" ");
> > String[] ss = new String[7];
> > for (int i = 0; i < cron.length; i++) {
> > ss[i] = cron[i];
> > }
> >
> > ScheduleExpression exp = new ScheduleExpression();
> > exp.second(0);
> > exp.minute(ss[1]);
> > exp.hour(ss[2]);
> > exp.dayOfWeek(ss[3]);
> > exp.dayOfMonth(ss[4]);
> > exp.month(ss[5]);
> > exp.year(ss[6]);
> >
> > System.out.println(toString(exp));
> >
> > Timer t = this.timerService.createCalendarTimer(exp);
> >
> > System.out.println("Created "+t);
> > }
> >
> > }
> >
> > output for this looks like this
> >
> > MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
> > getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12,
> getSecond()=0,
> > getStart()=null, getYear()=2013, getTimezone()=null]
> >
> > Created org.apache.openejb.core.timer.TimerImpl@298a0c11
> >
> > an after some seconds
> >
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a
> > org.apache.openejb.core.timer.TimerImpl@5f1e961a...
> >
> > any help is welcome
> >
> > TIA
> >
> > Leo
>
Re: doubt about timer service
Posted by Nrkkalyan <nr...@gmail.com>.
If you mean you would like your timer service to run every min 24/7 then you
You need only the following. exp.minutes("*/1").hour("*")
Hope I am clearly understanding your need.
Regards
/Kalyan
0733312584
PS: May have typos due to using mobile
On 28 dec 2013, at 19:53, "Leonardo K. Shikida" <sh...@gmail.com> wrote:
> Hi
>
> I'd like to start a calendar scheduled job for 1 minute from now.
>
> I was trying to assemble a cron expression like this, but instead, it's
> generating
> a lot of jobs (really)
>
> looks like something really stupid
>
> The code is as simple as this
>
> import java.util.Calendar;
> import java.util.GregorianCalendar;
>
> import javax.annotation.PostConstruct;
> import javax.annotation.Resource;
> import javax.ejb.ScheduleExpression;
> import javax.ejb.Singleton;
> import javax.ejb.Startup;
> import javax.ejb.Timeout;
> import javax.ejb.Timer;
> import javax.ejb.TimerService;
>
> @Singleton
> @Startup
> public class TimerEJB {
>
> @Resource
> private TimerService timerService;
>
> @Timeout
> public void executeTimer(Timer timer) {
> System.out.println(timer);
> }
>
> private String toString(ScheduleExpression schedule) {
> return "MyScheduleExpression [getDayOfMonth()=" +
> schedule.getDayOfMonth()
> + ", getDayOfWeek()=" + schedule.getDayOfWeek()
> + ", getEnd()=" + schedule.getEnd()
> + ", getHour()=" + schedule.getHour()
> + ", getMinute()=" + schedule.getMinute()
> + ", getMonth()=" + schedule.getMonth()
> + ", getSecond()=" + schedule.getSecond()
> + ", getStart()=" + schedule.getStart()
> + ", getYear()=" + schedule.getYear()
> + ", getTimezone()=" + schedule.getTimezone() + "]";
> }
>
> @PostConstruct
> public void create() {
>
> Calendar future = new GregorianCalendar();
> future.setTimeInMillis(System.currentTimeMillis() + 60000);
>
> int dayOfWeek = future.get(Calendar.DAY_OF_WEEK);
> String dayOfWeekName = null;
>
> switch (dayOfWeek) {
> case Calendar.MONDAY:
> dayOfWeekName = "Mon";
> break;
> case Calendar.TUESDAY:
> dayOfWeekName = "Tue";
> break;
> case Calendar.WEDNESDAY:
> dayOfWeekName = "Wed";
> break;
> case Calendar.THURSDAY:
> dayOfWeekName = "Thu";
> break;
> case Calendar.FRIDAY:
> dayOfWeekName = "Fri";
> break;
> case Calendar.SATURDAY:
> dayOfWeekName = "Sat";
> break;
> case Calendar.SUNDAY:
> dayOfWeekName = "Sun";
> break;
> }
>
> String cronExp = String.format("%1$s %2$s %3$s %4$s %5$s %6$s %7$s",
> future.get(Calendar.SECOND),
> future.get(Calendar.MINUTE),
> future.get(Calendar.HOUR_OF_DAY),
> dayOfWeekName,
> future.get(Calendar.DAY_OF_MONTH),
> future.get(Calendar.MONTH) + 1,
> future.get(Calendar.YEAR));
>
> String[] cron = cronExp.split(" ");
> String[] ss = new String[7];
> for (int i = 0; i < cron.length; i++) {
> ss[i] = cron[i];
> }
>
> ScheduleExpression exp = new ScheduleExpression();
> exp.second(0);
> exp.minute(ss[1]);
> exp.hour(ss[2]);
> exp.dayOfWeek(ss[3]);
> exp.dayOfMonth(ss[4]);
> exp.month(ss[5]);
> exp.year(ss[6]);
>
> System.out.println(toString(exp));
>
> Timer t = this.timerService.createCalendarTimer(exp);
>
> System.out.println("Created "+t);
> }
>
> }
>
> output for this looks like this
>
> MyScheduleExpression [getDayOfMonth()=28, getDayOfWeek()=Sat,
> getEnd()=null, getHour()=16, getMinute()=53, getMonth()=12, getSecond()=0,
> getStart()=null, getYear()=2013, getTimezone()=null]
>
> Created org.apache.openejb.core.timer.TimerImpl@298a0c11
>
> an after some seconds
>
> org.apache.openejb.core.timer.TimerImpl@5f1e961a
> org.apache.openejb.core.timer.TimerImpl@5f1e961a
> org.apache.openejb.core.timer.TimerImpl@5f1e961a
> org.apache.openejb.core.timer.TimerImpl@5f1e961a
> org.apache.openejb.core.timer.TimerImpl@5f1e961a
> org.apache.openejb.core.timer.TimerImpl@5f1e961a
> org.apache.openejb.core.timer.TimerImpl@5f1e961a...
>
> any help is welcome
>
> TIA
>
> Leo