Skip to Content
0
Former Member
Sep 07, 2012 at 09:27 AM

TimerService not available in start up hook ?

16 Views

Hello there,

I want to start a timer during @AppStartup-method. This works fine, when netweaver runs with only one server process. When this applications runs at NetWeaver with 2 server processes, the following error occurs :

Caused by: com.sap.engine.lib.injection.InjectionException: Injection on field timerService of instance test25.TEST25StartupManagerBean@2feaab94 failed. Could not get a value to be injected from the factory.
at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:115)
at com.sap.engine.lib.injection.InjectionMatrix.inject(InjectionMatrix.java:45)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_DependencyInjection.invoke(Interceptors_DependencyInjection.java:23)
... 48 more
Caused by: com.sap.engine.services.jndi.persistent.exceptions720.NameNotFoundException: Path to object does not exist. First missing component is [test25.TEST25StartupManagerBean], the whole lookup name is [java:comp/env/test25.TEST25StartupManagerBean/timerService].
at

...

The code:

public class TEST25StartupManagerBean implements TEST25StartupManagerLocal,Serializable {

private static final long serialVersionUID = 4012066785128839109L;

@Resource

private TimerService timerService;

private Location loc;

public TEST25StartupManagerBean() {

loc= Location.getLocation(this.getClass());

}

@AppStartup

public void startupHook()

{

SimpleLogger.log(Severity.INFO, Category.APPLICATIONS, loc, "startupHook:01", "start timer ");

Long days = 1L;

if(days!=null && days>0 )

{

long DAYS_IN_MILLISECONDS = 1000 * 60 * 60 * 24 * days;

Timer t = timerService.createTimer(Calendar.getInstance().getTime(),DAYS_IN_MILLISECONDS, 1);

}

}

}

Obviously the timerservice isnt avaiable during AppStartup, but only when more than one server process exist. What is wrong ?

Thanks for help

Ines