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<String> 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. <bean id="poolService" class="me.emi.PoolService"
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.