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<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/
>
>
> [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.