I have java class in JSF which act as a Scheduler and it runs every five seconds in background to perform some updates in DB.
since it is not declared as a bean in faces config or via annotation, i am not able to get session using
facesContext.getExternalContext().getSession(false);
Class scheduler{
public void Scheduler(){
HttpSession session = getSession(); // throughing null pointer Exception.
}
}
private HttpSession getSession()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
return session;
}
How can I get an object of session in this Scenario ?