c3p0
c3p0 copied to clipboard
Specify a custom Executor to run background threads
It would be useful if you could specify a custom Executor to run background tasks, rather than explicitly creating new threads in C3P0PooledConnectionPoolManager, so the background tasks can run on an existing thread pool instead of creating dedicated threads which are idle most of the time
hi,
I agree with this one, c3p0 creates a lot of threads, they would be best managed through an injected Executor.
thanks, Michele
On Friday, 15 July 2016, simonmcooper [email protected] wrote:
It would be useful if you could specify a custom Executor to run background threads, rather than explicitly creating new threads in C3P0PooledConnectionPoolManager, so the background tasks can run on an existing thread pool instead of creating dedicated threads which are idle most of the time
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/swaldman/c3p0/issues/76, or mute the thread https://github.com/notifications/unsubscribe-auth/ADtXnMWTltp24sZHKff_hBnTxL1j_mDkks5qV00RgaJpZM4JNNRl .
Sent from Gmail Mobile
@mrossi975 @ghost You have to do a bit of work yourself, but as of c3p0-0.10.0.x, this will be doable by extending AbstractExecutorTaskRunnerFactory.
That looks annoying, but extending it is simple, see for example FixedThreadPoolExecutorTaskRunnerFactory.
In this case, DataSources will create an Executor of their own, but you can implement it to look up an existing, shared Executor. (Just return false from taskRunnerOwnsExecutor(), so that when the task runner is closed, the Executor will not be.)
Thanks!
@mrossi975 @ghost I probably ought to have mentioned, to give your factory effect, you just set the java bean property taskRunnerFactoryClassName to your factory class, which is expected to offer a public, no-arg constructor.