multithreading - SessionScope and Scheduled threads -
in application have service performs heavy loading (parsing of different files) on creation. data metadata, wont change during runtime (localized strings, key/value mappings, etc.) therefore decided make service sessionscoped, don't need parse values every request. not applicationscoped make sure data refreshed, when user logs in again.
this works pretty well, need access service inside thread, run @schedule annotation. of course weld not , says: org.jboss.weld.context.contextnotactiveexception: weld-001303 no active contexts scope type javax.enterprise.context.sessionscoped
@singleton public class dailymails { @inject mailservice mailservice; //just named @inject groupdataservice groupdataservice; //stateless @inject localizationservice localizationservice; //sessionscoped @schedule(hour = "2", minute = "0", second = "0", dayofweek="mon,tue,wed,thu,fri", persistent = false) public void run() { //do work } } can manually create session @ point, can use sessionscoped service?
edit: know, service should not ne sessionscoped nor should hold data(-collections). in situation seems legit me avoid multiple file-system accesses.
i thought making service unscoped service , "cache" data in session scoped bean. need inject session bean service, again make service kind of "session scoped".
shouldn't work:
@inject @new localizationservice localizationservice; at least, that's how interpret specification.
Comments
Post a Comment