Reputation: 6086
My question is about this answer here that seems to work for my case (tomcat). However I see that it uses a newSingleThreadScheduledExecutor()
. In my case the periodical task that has to be executed could be long lasting and I want to make sure that it will not block my web site until it has completed (run as a separated Thread
). In addition I want to make sure that my task Runnable
will be able to share mySQL connection pool (through hibernate) that the web site is using.
So, is that still the correct approach or do I have to use something else?
Upvotes: 1
Views: 1515
Reputation: 11185
I want to make sure that it will not block my web site until it has completed (run as a separated Thread)
The HTTP connector thread pool and the thread pool allocated to run timer tasks are different. They are not dependent on each other and will not block your website.
In addition I want to make sure that my task Runnable will be able to share mySQL connection pool (through hibernate) that the web site is using. So, is that still the correct approach or do I have to use something else?
Configure a common connection pool using a framework like commons DBCP and lookup the resource on the JNDI. Once you lookup that DataSource
and the work on the connection has terminated, return the connection back to the pool.
The approach is fine.
Upvotes: 2