1

I am continually running out of database connections using a DataSource, Spring and Quartz. As seen below, my TaskExecutor's maximumPoolSize is 30. So, is that the maximum # of connections my setup will use?

With a corePoolSize = 10, is my setup holding 10 database connections continually?

I am using a Spring TaskExecutor which I create like this and register with my Spring SchedulerFactoryBean.

I create a TaskExecutor like this:

public TaskExecutor schedulerTaskExecutor() {

        int corePoolSize = 10;
        int maxPoolSize = 30;

        long keepAliveTime = 30000;
        int internalQueueCapacity = 1000;
        boolean allowCoreThreadTimeOut = true;

        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
                corePoolSize, // core pool size
                maxPoolSize, // max pool size
                keepAliveTime,
                TimeUnit.SECONDS, 
                new LinkedBlockingQueue<Runnable>(internalQueueCapacity)) ;
        threadPool.allowCoreThreadTimeOut(allowCoreThreadTimeOut);

        NamedThreadFactory threadFactory = new NamedThreadFactory("SCHEDULER-");
        threadPool.setThreadFactory(threadFactory);

        return new TaskExecutorAdapter(threadPool);

    }
Jason
  • 2,006
  • 3
  • 21
  • 36
  • The size of your connection pool has nothing to do with how many threads your task executor can have. If you have 10 concurrent threads it might be wise to to have a large enough connection pool. HOwever generally speaking if you have timeouts you are probably doing things not entirely in the right way. Are you messing around with JDBC connections yourself instead of using JPA or Spring `JdbcTemplate`? – M. Deinum Oct 24 '18 at 14:02
  • We use JPA exclusively. – Jason Oct 24 '18 at 17:43
  • Even that can be wrongly configured... There can be a lot that influences that and only adding a configuration for the task executor is just a very small part of the puzzle. – M. Deinum Oct 24 '18 at 17:58

0 Answers0