Announcement Announcement Module
Collapse
No announcement yet.
TaskScheduler creates new threads on every schedule Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TaskScheduler creates new threads on every schedule

    Hi All,

    I am new to Spring Integrations Framework, I am trying to use TaskScheduler to schedule few tasks to run on a specified time.
    whenever the worker thread completes the job, the scheduler triggers a new scheduler thread for the next run but the completed thread never gets killed or being re-used. I am using the below code to do the same.

    I have defined the task scheduler pool size as 15
    Code:
    <task:scheduler id="taskScheduler" pool-size="15"  />
    
    <bean id="eventSchedule" class="com.company.example.EventSchedule">
           <property name="taskScheduler" ref="taskScheduler" />
    </bean>
    Scheduling the tasks
    Code:
    ...
    ...
    
    String cronTime = "0 0/2 * ? * MON-FRI";
    EventSchedule eventSchedule = (EventSchedule)context.getBean("eventSchedule");
    
    for(int i=0;i<7;i++){
        eventSchedule.getTaskScheduler().schedule(RunnableTaskExecutor, new CronTrigger(cronTime));
    }
    
    ...
    ...
    
    
    public class RunnableTaskExecutor implements Runnable {
    	
    	public void run() {
    	
    		execute();
    	}
    	
    	private void execute(){
    		...
    		System.out.println("do something");
    		...
    	}
    }
    after the first run which created 7 threads, for the second run, i see 7 more new threads created and the completed ones were not re-used. After the second schedule, only one thread runs for the third time.
    I am confused what would have gone wrong.

    Please help me understand what's wrong in this code.

    Thanks,
    Subbhu
Working...
X