Re: newFixedThreadPool in struts2
[Try2] . Each user login session create one fixedPool . When user logout, fixedPool.shutdown() What about if users do not call logout action. Where and how the fixedPool to be shutdown? Is there a way to auto shutdown after period of time? You can write your own listener by implementing HttpSessionListener and call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ I will try1 which can be used/shared by all login users or 2 used by per login user session then. set session as it's life-time, then it seems you still simply can use that spring bean with `scope` set to `session`. session scope can be a bad choice if your "...actions such as send email, etc" take too long to being completed because user can log out or session can being expired in the middle of their executions! For users logout action, I could try to check based on future.get() to help users know there are processes still running. I see but I think you should not force user to not logout. Consider a user which uses a shared computer of an airport and now wants to logout to not miss her flight :) if you force her to being loged in, but she leaves that shared computer and this raises security issues for her as next person can use her session :( To help users know there are process running, comments/warning messages are shown to users. Users can still logout, and tasks may be lost. And users may try the same steps in the next login session. Tasks submitted through threads or action classes are the same, if users logout in the middle of process, users will need to login again and try the same steps. For session expired, this is not clear to me. In web.xml, session-timeout=60 for example. Users will be considered auto-logout only if users have not use any features(no active actions) for more than 60 mins. If there are sub-threads submitted by action class(struts2 is thread-safe, I could consider the action class as a main thread?), and if sub-threads have not completed, wouldn't web.xml consider there are still active actions? No, it just invalidates the session. And developer has to clean up when a session is about to be invalidated (HttpSessionListener. sessionDestroyed). Users logout is simple: (1) session.getAttribute(fixpool); fixpool.shutdown; (2) for(String attribute: attributes) { session.removeAttribute(attribute); } (3) session.invalidate(); For auto-session timeout (not logout by users), in sessionDestroyed method, I am not able to call/run (1). I will try HttpSessionBindingListener and see if this helps. So, wouldn't it be that user-session auto-expired only when: (1) users have not use any features and (2) All sub-threads submitted by users through action classes have completed No, it doesn't consider what you have in session. It simply invalidates. I didn't mean session values, I mean fixPool.submit(tasks) have not completed. To be more clear: (1) User login: fixpool is created and saved into session (2) In Action class: session.get(fixpool); fixpool.submit(tasks); (3) web.xml session-timeout (3.1) If users click any features in webapp, web.xml.session-timeout are not called (3.2) If fixpool.tasks are running (called by action class), session-timeout are still called? So, web.xml.session-timeout does not check if threads submitted through action class are completed or not Thanks a lot. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: newFixedThreadPool in struts2
It's still accessible: public void sessionCreated(HttpSessionEvent hse) { final HttpSession session = hse.getSession(); logger.debug("session created"); session.setAttribute(KEY, new Clickstream()); } public void sessionDestroyed(HttpSessionEvent hse) { final HttpSession session = hse.getSession(); // session.getAttribute(KEY) => failed. logger.debug("session destroyed"); } In sessionDestroyed method, I could only get sessionID as shown in the link below, but not session.getAttribute(KEY). I will try HttpSessionBindingListener, and see if this helps. Thanks. -- Actions that I tried to implement: (1) Save fixThreadPool into session (2) Submit tasks through fixpool (3) When session auto-timeout call fixpool.shutdown https://stackoverflow.com/questions/19046976/not-getting-session-attributes-in-sessiondestroyed-method-of-httpsessionlisten - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: newFixedThreadPool in struts2
On 2/10/2018 12:32 AM, Emi wrote: > Hello Yasser, >> You can write your own listener by implementing HttpSessionListener >> and call shutdown in it's `sessionDestroyed` method. Please see [1]. >> [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ > In HttpSessionListener, it seems that there are no session attributes > anymore. So, there is no way for me to do the following in the listener > class: > > fixPool = session.getAttribute('fixpool_name'); > fixPool.shutdown(); > > So, the only possible way is through springframework config, right? Hello Emi, The documentation says "Receives notification that a session is about to be invalidated" at [1] i.e. "it's about", so still should be accessible (please try HttpSessionEvent.getSession of it's parameter to see). Please also consider when you call session.invalidate in logout, then this method also may being called also. Sincerely, Yasser. [1] https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionListener.html - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: newFixedThreadPool in struts2
On 2/9/2018 10:20 PM, Emi wrote: > [Try2] . Each user login session create one fixedPool . When user > logout, fixedPool.shutdown() What about if users do not call > logout action. Where and how the fixedPool to be shutdown? Is > there a way to auto shutdown after period of time? You can write your own listener by implementing HttpSessionListener and call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ >>> I will try1 which can be used/shared by all login users or 2 used by >>> per login user session then. >> set session as it's life-time, then it seems you still simply can use >> that spring bean with `scope` set to `session`. >> session scope can be a bad choice if your "...actions such as send >> email, etc" take too long to being completed because user can log out >> or session can being expired in the middle of their executions! > For users logout action, I could try to check based on future.get() to > help users know there are processes still running. I see but I think you should not force user to not logout. Consider a user which uses a shared computer of an airport and now wants to logout to not miss her flight :) if you force her to being loged in, but she leaves that shared computer and this raises security issues for her as next person can use her session :( > > For session expired, this is not clear to me. In web.xml, > session-timeout=60 for example. Users will be considered auto-logout > only if users have not use any features(no active actions) for more than > 60 mins. > > If there are sub-threads submitted by action class(struts2 is > thread-safe, I could consider the action class as a main thread?), and > if sub-threads have not completed, wouldn't web.xml consider there are > still active actions? > No, it just invalidates the session. And developer has to clean up when a session is about to be invalidated (HttpSessionListener. sessionDestroyed). > So, wouldn't it be that user-session auto-expired only when: > (1) users have not use any features and > (2) All sub-threads submitted by users through action classes have > completed > No, it doesn't consider what you have in session. It simply invalidates. > If I misunderstood threads usage in struts2 framework, please kindly > correct me. > These are not about Struts. Underlying servlet implementation (e.g. tomcat) does these. Sincerely, Yasser.
Re: newFixedThreadPool in struts2
in struts this is accomplished implementing org.apache.struts2.interceptor.createSessionInterceptor configured in interceptor-ref name in struts-config.xml <action name="someAction" class="com.examples.SomeAction"> * <interceptor-ref name="createSession"/> afterwards you can access the HttpServletRequest: HttpServletRequest req=ServletActionContext.getServletContext().getRequest() HttpSession session=req.getSession(); get all the params from session you need HTH Martin __ From: Emi Sent: Friday, February 9, 2018 4:02 PM To: Struts Users Mailing List Subject: Re: newFixedThreadPool in struts2 Hello Yasser, > You can write your own listener by implementing HttpSessionListener > and call shutdown in it's `sessionDestroyed` method. Please see [1]. > [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ Session timeout handling in Java | My Java Recipes<http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/> www.myjavarecipes.com Hi Reader, Recently I got requirement from customer that how much time user is spending on web application. Requirement is simple, for this we just need to record ... In HttpSessionListener, it seems that there are no session attributes anymore. So, there is no way for me to do the following in the listener class: fixPool = session.getAttribute('fixpool_name'); fixPool.shutdown(); So, the only possible way is through springframework config, right? Thanks a lot. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: newFixedThreadPool in struts2
It's still accessible: public void sessionCreated(HttpSessionEvent hse) { final HttpSession session = hse.getSession(); logger.debug("session created"); session.setAttribute(KEY, new Clickstream()); } public void sessionDestroyed(HttpSessionEvent hse) { final HttpSession session = hse.getSession(); logger.debug("session destroyed"); } On Fri, Feb 9, 2018 at 3:02 PM, Emi wrote: > Hello Yasser, > >> You can write your own listener by implementing HttpSessionListener and >> call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] >> http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ >> > In HttpSessionListener, it seems that there are no session attributes > anymore. So, there is no way for me to do the following in the listener > class: > > fixPool = session.getAttribute('fixpool_name'); > fixPool.shutdown(); > > So, the only possible way is through springframework config, right? > > Thanks a lot. > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: newFixedThreadPool in struts2
Hello Yasser, You can write your own listener by implementing HttpSessionListener and call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ In HttpSessionListener, it seems that there are no session attributes anymore. So, there is no way for me to do the following in the listener class: fixPool = session.getAttribute('fixpool_name'); fixPool.shutdown(); So, the only possible way is through springframework config, right? Thanks a lot. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: newFixedThreadPool in struts2
Firstly you should decide what do you like about life-time of that thread pool without being worry about calling shutdown. All your examples have solutions to call shutdown which I described below... Please read below [Try1] . By springframe work setup ThreadPool . In action class, use fixedPool Future f1 = fixedPool.submit(() -> { ...actions such as send email, etc }); So, there will be NO shutdown in action class fixedPool.shutdown(); will be maintained by spring config? You can set your bean `destroy-method` and call shutdown in that method. e.g. init-method="initPool" destroy-method="shutdownPool"> [Try2] . Each user login session create one fixedPool . When user logout, fixedPool.shutdown() What about if users do not call logout action. Where and how the fixedPool to be shutdown? Is there a way to auto shutdown after period of time? You can write your own listener by implementing HttpSessionListener and call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ I will try1 which can be used/shared by all login users or 2 used by per login user session then. set session as it's life-time, then it seems you still simply can use that spring bean with `scope` set to `session`. session scope can be a bad choice if your "...actions such as send email, etc" take too long to being completed because user can log out or session can being expired in the middle of their executions! For users logout action, I could try to check based on future.get() to help users know there are processes still running. For session expired, this is not clear to me. In web.xml, session-timeout=60 for example. Users will be considered auto-logout only if users have not use any features(no active actions) for more than 60 mins. If there are sub-threads submitted by action class(struts2 is thread-safe, I could consider the action class as a main thread?), and if sub-threads have not completed, wouldn't web.xml consider there are still active actions? So, wouldn't it be that user-session auto-expired only when: (1) users have not use any features and (2) All sub-threads submitted by users through action classes have completed If I misunderstood threads usage in struts2 framework, please kindly correct me. Thanks a lot.
Re: newFixedThreadPool in struts2
On 2/8/2018 8:51 PM, Emi wrote: >> Firstly you should decide what do you like about life-time of that >> thread pool without being worry about calling shutdown. All your >> examples have solutions to call shutdown which I described below... >> Please read below >>> [Try1] . By springframe work setup ThreadPool . In action class, use >>> fixedPool Future f1 = fixedPool.submit(() -> { ...actions >>> such as send email, etc }); So, there will be NO shutdown in >>> action class fixedPool.shutdown(); will be maintained by >>> spring config? >> You can set your bean `destroy-method` and call shutdown in that >> method. e.g. > init-method="initPool" destroy-method="shutdownPool"> >>> [Try2] . Each user login session create one fixedPool . When user >>> logout, fixedPool.shutdown() What about if users do not call logout >>> action. Where and how the fixedPool to be shutdown? Is there a way >>> to auto shutdown after period of time? >> You can write your own listener by implementing HttpSessionListener >> and call shutdown in it's `sessionDestroyed` method. Please see [1]. >> [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ > Thank you very much Yasser. The information are very helpful! > > I will try1 which can be used/shared by all login users or 2 used by per > login user session then. > You're welcome :) I rethought and if you decided to set session as it's life-time, then it seems you still simply can use that spring bean with `scope` set to `session`. But session scope can be a bad choice if your "...actions such as send email, etc" take too long to being completed because user can log out or session can being expired in the middle of their executions! Sincerely, Yasser.
Re: newFixedThreadPool in struts2
Firstly you should decide what do you like about life-time of that thread pool without being worry about calling shutdown. All your examples have solutions to call shutdown which I described below... Please read below [Try1] . By springframe work setup ThreadPool . In action class, use fixedPool Future f1 = fixedPool.submit(() -> { ...actions such as send email, etc }); So, there will be NO shutdown in action class fixedPool.shutdown(); will be maintained by spring config? You can set your bean `destroy-method` and call shutdown in that method. e.g. init-method="initPool" destroy-method="shutdownPool"> [Try2] . Each user login session create one fixedPool . When user logout, fixedPool.shutdown() What about if users do not call logout action. Where and how the fixedPool to be shutdown? Is there a way to auto shutdown after period of time? You can write your own listener by implementing HttpSessionListener and call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ Thank you very much Yasser. The information are very helpful! I will try1 which can be used/shared by all login users or 2 used by per login user session then.
Re: newFixedThreadPool in struts2
Hello Emi, Firstly you should decide what do you like about life-time of that thread pool without being worry about calling shutdown. All your examples have solutions to call shutdown which I described below... Please read below On 2/8/2018 7:02 PM, Emi wrote: > Hello, > > Can you suggest the best way to setup newFixedThreadPool in struts2 > webapp please? > > [Try1] > . By springframe work setup ThreadPool > . In action class, use fixedPool > Future f1 = fixedPool.submit(() -> { ...actions such as send > email, etc }); > > So, there will be NO shutdown in action class > fixedPool.shutdown(); will be maintained by spring config? You can set your bean `destroy-method` and call shutdown in that method. e.g. > > > > [Try2] > . Each user login session create one fixedPool > . When user logout, fixedPool.shutdown() > > What about if users do not call logout action. Where and how the > fixedPool to be shutdown? > Is there a way to auto shutdown after period of time? You can write your own listener by implementing HttpSessionListener and call shutdown in it's `sessionDestroyed` method. Please see [1]. [1] http://www.myjavarecipes.com/tag/session-timeout-handling-in-java/ > > > [Try3] > . In each action method > Create fixedPool > submit/future run... > fixedPool.shutdown() > > This way, the benefit is that fixedPool is shutdown for sure after > thread completes. > But each action is going to create one threadpool. Yes as you already mentioned, it's not a good idea at all because of it's bad performance. > > > Any suggestions about the best way to use "FixedThreadPool" in struts2 > web framework please? > Please read beginning of this email :) > Thanks a lot! Sincerely, Yasser.
newFixedThreadPool in struts2
Hello, Can you suggest the best way to setup newFixedThreadPool in struts2 webapp please? [Try1] . By springframe work setup ThreadPool . In action class, use fixedPool Future f1 = fixedPool.submit(() -> { ...actions such as send email, etc }); So, there will be NO shutdown in action class fixedPool.shutdown(); will be maintained by spring config? [Try2] . Each user login session create one fixedPool . When user logout, fixedPool.shutdown() What about if users do not call logout action. Where and how the fixedPool to be shutdown? Is there a way to auto shutdown after period of time? [Try3] . In each action method Create fixedPool submit/future run... fixedPool.shutdown() This way, the benefit is that fixedPool is shutdown for sure after thread completes. But each action is going to create one threadpool. Any suggestions about the best way to use "FixedThreadPool" in struts2 web framework please? Thanks a lot!