I have created a class StartupListener implements ServletContextListener. Inside
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
I create a timer which will be executed every 30 seconds. Inside this timer I want to set a parameter from my @ApplicationScoped - Bean in order to display the information from the timer to my website.
Here is what I did so far:
StartupListener.java
package de.whatever;
import java.util.Timer;
import javax.naming.Context;
public class CargoServiceStartupListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
....
ModuleScannerTask task = new ModuleScannerTask(contextEvent.getServletContext());
Timer timer = new Timer("Scanner");
timer.schedule(task, 0, 10000);
ModuleScannerTask.java
package de.whatever;
import java.util.Enumeration;
public class ModuleScannerTask extends TimerTask{
private ServletContext context;
public ModuleScannerTask (ServletContext context) {
this.context = context;
}
@Override
public void run() {
System.out.println("Start scanning ...");
...
ModuleBean.java
package de.whatever;
@ManagedBean (name="modOverview")
@ApplicationScoped
public class ModuleOverviewBean {
private String randomData;
My question is how to set data into randomData field in my application bean.
I read that I could load the attribute "modOverview" from the ServletContext, but that returns null.
What would be the correct way to load and set the values?
I am using JBoss (without spring).
Thanks Hauke