title: Java 8 repeatable custom annotations
body: <p>I know about basic annotations in Java like <code>@Override</code> etc. </p>
  
  <pre><code>Annotations are only metadata and they do not contain any business logic.
  </code></pre>
  
  <p>I am going through repeating annotations from Oracle <a href="https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html" rel="noreferrer">documentation</a> page to understand <em>Java 8</em> new feature. </p>
  
  <p>For example, you are writing code to use a "<em>timer service that enables you to run a method at a given time or on a certain schedule, similar to the UNIX cron service</em>". Now you want to set a timer to run a method, <code>doPeriodicCleanup</code>, on the last day of the month and on every Friday at 11:00 p.m. To set the timer to run, create an <code>@Schedule</code> annotation and apply it twice to the doPeriodicCleanup method.</p>
  
  <pre><code>@Schedule(dayOfMonth="last")
  @Schedule(dayOfWeek="Fri", hour="23")
  public void doPeriodicCleanup() { ... }
  </code></pre>
  
  <h3>Declare a Repeatable Annotation Type</h3>
  
  <blockquote>
    <p>The annotation type must be marked with the @Repeatable meta-annotation. The following example defines a custom @Schedule repeatable annotation type:</p>
  </blockquote>
  
  <pre><code>import java.lang.annotation.Repeatable;
  
  @Repeatable(Schedules.class)
  public @interface Schedule {
      String dayOfMonth() default "first";
      String dayOfWeek() default "Mon";
      int hour() default 12;
  }
  </code></pre>
  
  <h3>Declare the Containing Annotation Type</h3>
  
  <blockquote>
    <p>The containing annotation type must have a value element with an array type. The component type of the array type must be the repeatable annotation type. The declaration for the Schedules containing annotation type is the following:</p>
  </blockquote>
  
  <pre><code>public @interface Schedules {
      Schedule[] value();
  }
  </code></pre>
  
  <p><strong>I did not understand use and usage of @Schedules annotation. How does it work for below method now?</strong> . </p>
  
  <pre><code>public void doPeriodicCleanup() { ... }
  </code></pre>
  
  <p>Thanks in advance.</p>