title: Spring MVC WebApp : @schedule: java-sdk-http-connection-reaper : Failed to Stop
body: <p>I have a Web Application(using Spring 3.1) which uses  @Scheduled Annotation for periodically executing a worker task (scheduled delay). The worker task opens up a connection to AWS DynamoDb and does some DB read/updates. When I stop the webapp (from Tomcat manager) I get this message in catalina.out: </p>
  
  <p><em>"SEVERE: The web application [] appears to have started a thread named [java-sdk-http-connection-reaper] but has failed to stop it. This is very likely to create a memory leak."</em></p>
  
  <p>I get a feeling that this has something to do with my scheduled task still running even after Tomcat stops.</p>
  
  <pre><code>@Service
  public class TaskScheduler implements ApplicationListener&lt;ContextClosedEvent&gt;{
  
  @Autowired
  private WorkerTask workerTask;
  
  AmazonDynamoDBClient myDbConn = null;
  
     private TaskScheduler() {    
     myDbConn = new AWSConnector("aws.properties").getDynamoConnection();
     }
  
  /*
   * Will be repeatedly called, 10 seconds after the finish of the previous 
   * invocation.
   */
  @Scheduled(fixedDelay=100000)
  public void process() {
      System.out.println("Scheduling worker task");
              //worker task does some db read/writes
      Future&lt;String&gt; status = workerTask.work(myDbConn);
      if (status.isDone()) {
          System.out.println("Completed Task");
          return;
      }
  
  }
  
  @Override
  public void onApplicationEvent(ContextClosedEvent arg0) {
      if(event instanceof ContextClosedEvent) {   
        // TODO Auto-generated method stub
        if(myDbConn != null) {
          this.myDbConn.shutdown();
        }
            }
  
  }
  </code></pre>
  
  <p>dispatcher-servlet.xml:</p>
  
  <pre><code>&lt;task:annotation-driven scheduler="taskScheduler"/&gt;
  &lt;task:scheduler id="taskScheduler" pool-size="2"/&gt;
  ......
  &lt;bean id="TaskScheduler" class="com.sample.TaskScheduler"/&gt;
  </code></pre>
  
  <p>Am I doing this correctly? a) I don't explicitly start the TaskScheduler. So i'm assuming spring takes care of starting this service. The 'this.myDbConn.shutdown()' is called. Despite this, I get the error. I'm using Spring MVC. </p>