title: How to run a particular task every Friday in a week at any time using ScheduledExecutorService?
body: <p>I am trying to run a certain task every Friday in a week at any time. So I decided to use <code>ScheduledExecutorService</code> for this but so far I have seen examples which shows how to run task every few minutes.</p>
  
  <p>Below is my code which I adopted to run every day at 5 AM in the morning. How do I use this to run task every Friday in a week at any time?</p>
  
  <pre><code>public static void main(String[] args) {
  
      ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5);
      Date aDate = new Date();
      Calendar with = Calendar.getInstance();
      with.setTime(aDate);
  
      int hour = with.get(Calendar.HOUR_OF_DAY);
      int intDelayInHour = hour &lt; 5 ? 5 - hour : 24 - (hour - 5);
  
      System.out.println("Current Hour: " + hour);
      System.out.println("Comuted Delay for next 5 AM: " + intDelayInHour);
  
      scheduler.scheduleAtFixedRate(new Runnable() {
          public void run() {
              try {
                  getDataFromDatabase();
              } catch (Exception ex) {
                  ex.printStackTrace(); // or loggger would be better
              }
          }
      }, intDelayInHour, 24, TimeUnit.HOURS);
  }
  
  protected static void getDataFromDatabase() {
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>Can anyone provide an example how would I do this?</p>