title: Switch between using ScheduledExecutorService and delay-free File Read
body: <p>To provide context, I am taking a reasonably long CSV file with one column of values providing the mean daily temperature from 1960-2016 and am reading them with a <code>BufferedReader</code> like so:</p>
  
  <pre><code>BufferedReader br = new BufferedReader(new FileReader(new File("src/dailyTemp.csv")));
  </code></pre>
  
  <p>I also have a Swing Application that provides a <code>Boolean</code> value, <code>slowSpeed</code>, to declare whether or not the <code>ScheduledExecutorService</code> should be ran. i.e. Whether or not it should be slow/fast.</p>
  
  <p>The current purpose of this application is to simply adjust whether the next value read is returned instantly or if it is instead scheduled. </p>
  
  <pre><code>public static void main(String[] args) throws IOException
  {
      startGraph(); //This is the GUI that provides the state of the slowSpeed variable
  
      final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
      executorService.scheduleAtFixedRate(Main::readFileSlow, 0, 500, TimeUnit.MILLISECONDS);
  
      BufferedReader br = new BufferedReader(new FileReader(new File("src/dailyTemp.csv")));
      String newValue = "";
  
      while (newValue != null)
      {
          if (slowSpeed)
          {
              newValue = readFileSlow(newValue, br);
          } else
          {
              newValue = readFileFast(newValue, br);
          }
          totalCount++;
      }
      br.close();
      System.out.println("FIN");
  }
  
  public static String readFileSlow(String newValue, BufferedReader br) throws IOException
  {
      while ((newValue = br.readLine()) != null)
      {
          System.out.println(newValue);
          return newValue;
      }
      return null;
  }
  
  public static String readFileFast(String newValue, BufferedReader br) throws IOException
  {
      while ((newValue = br.readLine()) != null)
      {
          System.out.println(newValue);
          return newValue;
      }
      return null;
  }
  </code></pre>
  
  <p>A necessary consideration is that the <code>Reader</code> cannot restart, and therefore the <code>while</code> loop exists to check that.</p>
  
  <p>The main issue I am having, is that the <code>readFileSlow()</code> function cannot take a variable as therefore it is not a <code>Runnable</code> and cannot be controlled by the <code>ScheduledExecutorService</code>.</p>
  
  <p>EDIT 1</p>
  
  <p>Here is my primitive version that reasonably shows how it works to switch:</p>
  
  <pre><code>public class Main
  {
      static Boolean slowSpeed = true;
  
      public static void main(String[] args) throws IOException, InterruptedException
      {
          startGraph();
  
          BufferedReader br = new BufferedReader(new FileReader(new File("src/dailyTemp.csv")));
  
          String newValue;
  
          while ((newValue = br.readLine()) != null)
          {
              if (slowSpeed)
              {
                  System.out.println(newValue);
                  doSomething(newValue);
  
                  TimeUnit.MILLISECONDS.sleep(500);
              } else
              {
                  System.out.println(newValue);
                  doSomething(newValue);
              }
              totalCount++;
          }
          br.close();
          System.out.println("FIN");
      }
  
      public static void toggleSpeed(Boolean newSpeed)
      {
          slowSpeed = newSpeed;
          System.out.println(slowSpeed);
      }
  }
  </code></pre>