title: How to run only one TimerTask?
body: <p>I use stomp to send data A every 2 seconds and data B every 10 minutes when the websocket connection is complete.</p>
  <p>So I divided the timerTask and implemented it.</p>
  <p>works fine though. In addition, when websockets are connected, the same timerTask is called and the number of connected websockets is called continuously.</p>
  <p>I need a &quot;don't call if Timertask is already running&quot; workaround.</p>
  <pre><code>
  //method called by controller
  public void publish(DateParam param, CustomLuluSession session) throws BizException {
          sendTrend(param, session);   //every 2 seconds
          sendIssueKeyword(param, session); //every 10 minutes
  }
  
  /*
  sendTrend and sendIssueKeyword
  is implemented the same, only the set time is different, so I will register only one as an example.
  */
  
  public void sendTrend(DateParam param, CustomLuluSession session) throws BizException {
      TimerTask task = trendTimerTask(param, session);
  
      final Timer timer = new Timer();
      timer.schedule(task, 0, TWO_SECOND);
  }
      
  public TimerTask trendTimerTask(DateParam param, CustomLuluSession session) throws BizException {
      TimerTask tempTask = new TimerTask() {
          @Override
          public void run() {
              try {
                  if (getSession() == 0) this.cancel();
                  getTrendInfo(param, session);
              } catch (BizException e) {
                  throw new RuntimeException(e);
              }
          }
      };
      return tempTask;
  }
  
  // Access the db to get data and send it to the client
  public void getTrendInfo(DateParam param, CustomLuluSession session) throws BizException {
  FindInquiryTrendResult inquiryTrend = inquiryFacade.findInquiryTrend(param, session);
  messagingTemplate.convertAndSend(ROOM_ID, inquiryTrend);
  }
  
  
  </code></pre>