This content has been marked as final.
Show 7 replies
-
1. Re: @Startup not working
javabr May 22, 2007 11:40 AM (in response to maniappan)Hi,
It is working for me: (take a loog on @Create)@Startup(depends="manager") @Name("controller") @Scope(ScopeType.APPLICATION) public class Controller { @In(create=true) private Manager manager; @Create public void create() throws Exception { manager.schedule(); } }
@Name("manager") @Scope(ScopeType.APPLICATION) public class Manager { private static Date MIDNIGHT = null; @In(create = true) Job sendNotificationsToScheduledTasks; public void schedule() { Calendar calendar = GregorianCalendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 1); calendar.set(Calendar.SECOND, 1); MIDNIGHT = calendar.getTime(); System.out.print(MIDNIGHT); sendNotificationsToScheduledTasks.execute(MIDNIGHT, Frequency.DAILY.getInterval()); }
I also had must to take the jboss timer off.
rgds
Leo -
2. Re: @Startup not working
javabr May 22, 2007 11:42 AM (in response to maniappan)opsss.
and also de Job interface:@Local public interface Job { @Asynchronous @Transactional public Timer execute(@Expiration Date startDate, @IntervalDuration long interval); }
-
3. Re: @Startup not working
maniappan May 22, 2007 12:34 PM (in response to maniappan)Hi Leo,
I earlier tried it the way you had done[start it in application scope] and it worked. I want to move it to Startup.
Cheers, Mani -
4. Re: @Startup not working
javabr May 22, 2007 12:40 PM (in response to maniappan)Oooohh I am sorry...
I am fresh meat here.. so I am just using what I am looking around.
If I figure out something I back to u.
bests
Leo -
5. Re: @Startup not working
quilleashm May 22, 2007 2:47 PM (in response to maniappan)In your example this
public void MySchedule()
Is wrong. That's not a constructor it's a method. Remove the void.
You can use the constructor method but a better way is to use the @Create annotation instead.@Entity @Name("mySchedule") @Table(name="my_schedule") @Scope(ScopeType.SESSION) @Startup public class MySchedule implements Serializable, { @Create public void create() { MyScheduleHome msh = (MyScheduleHome) Component.getInstance("myScheduleHome"); msh.Schedule(); log.debug("Timer activated"); } //Rest of the getters/setters for table. ... }
I would also suggest having @Entity and @Startup is bad practice. Your entity object should be relatively clean and the scheduling code should probably be in a session bean that may inject/create the entity bean.
Cheers.
Mike. -
6. Re: @Startup not working
maniappan May 23, 2007 12:19 AM (in response to maniappan)Mike,
I renamed to create as suggested by you and made it a APPLICATION Scope. Also had to add @Local since JNDI couldn't lookup the object during start and it has started working.
Thanks, Mani. -
7. Re: @Startup not working
gavin.king May 24, 2007 8:42 AM (in response to maniappan)Since it is a session scope component, it starts when the session starts, not when the application starts.