-
Notifications
You must be signed in to change notification settings - Fork 8.6k
large_amount_datasource_cn
温绍 edited this page Nov 20, 2017
·
2 revisions
缺省情况下,一个DruidDataSource会使用两个线程分别用于创建连接和销毁或检测连接。在分库分表的某些场景,可能需要数百甚至数千个数据库,因此会创建大量的线程。
DruidDataSource提供了createScheduler和destroyScheduler这两个配置,用于多个DruidDataSource公用创建连接池和销毁连接池。
ScheduledExecutorService createScheduler = ...;
ScheduledExecutorService destroyScheduler = ...;
DruidDataSource ds0 = ...;
DruidDataSource ds1 = ...;
ds0.setCreateScheduler(createScheduler);
ds1.setCreateScheduler(createScheduler);
ds0.setDestroyScheduler(destroyScheduler);
ds1.setDestroyScheduler(destroyScheduler);