finally I decided to do the refreshing cycle backed trough the EJB Timer Service.
This is my solution:
The @ApplicationScoped Bean (NewsController):
@ApplicationScoped
public class NewsController extends BaseController implements Serializable {
private static final long serialVersionUID = 1L;
@PersistenceContext
protected EntityManager em;
private List<News> newsList;
public NewsController() {
}
@PostConstruct
public void init() throws ExecutionException {
getAvailableNews();
}
public void getAvailableNews() {
if (newsList == null) {
newsList = new LinkedList<News>();
Query q = em.createNativeQuery(
"SELECT * FROM news WHERE sysdate BETWEEN ab AND bis+1",
News.class);
@SuppressWarnings("unchecked")
List<News> result = q.getResultList();
for (News n : result)
newsList.add(n);
}
}
public List<News> getNewsList() {
return newsList;
}
public void setNewsList(List<News> newsList) {
this.newsList = newsList;
}
}
I addede additionally a @Stateless Bean (NewsScheduler) which calls my getAvailableNews() every 10 miuntes in the NewsController:
@Stateless
public class NewsScheduler {
@Inject
NewsController newsController;
@Schedule(hour = "*", minute = "*/5")
public void reload() {
System.out.println("---------------- Laden der News aus der DB --------------");
newsController.setNewsList(null);
newsController.getAvailableNews();
}
}