title: Timer function not running. Java
body: <p>I have a question relating to the timer function. I have managed to find the cause of my problem, but I'm not sure on how to address it. I will give you an overview of my function. It will first execute the cost() function, with a background thread working. However, what I realize was that my cost() function failed to load right at the beginning. Secondly, it's program to run every 60 secs which it failed as well. I check my code for my cost() function and it works fine if I call it down without the timer function. Could it be my Opencsv() function? The question is it due to constraint of the timer function or is there ways to address this issue?</p>
  
  <pre><code>public static void main(String[] args)  {
    launch(EVschedulerApp.class, args);
  
    Timer timer = new Timer();
    // timer.scheduleAtFixedRate(new Cost(), 10*1000, 10*1000);
  
    timer.scheduleAtFixedRate(new Cost() {
  
        @Override
          public void run() {
          new Thread(new Runnable() {
              public void run() {
                File file = new File("D:/test.csv");
                if(file != null){
                  try {
                    Opencsv csv = new Opencsv();
  
                    csv.Csvreader();
                  } catch (IOException ex) {
                    Logger.getLogger(EVschedulerApp.class.getName()).log(Level.SEVERE, null, ex);
                  }
  
                }
                else {
  
                  try {
                    Thread.sleep(1000);
                  } catch (InterruptedException e) {}
                }
              }
            }).start();
        }
  </code></pre>
  
  <p>Opencsv class file: </p>
  
  <pre><code>public class Opencsv {
  
    public void Csvreader() throws IOException {
      try {
        // TODO code application logic here
  
        CSVReader reader = new CSVReader(new FileReader("D:/Test.csv"));
  
        String [] nextLine;
        while ((nextLine = reader.readNext()) != null) {
          // nextLine[] is an array of values from the line
          System.out.println(nextLine[0] + " " + nextLine[1]+ " " + nextLine[2]+ " " + nextLine[3]);
        }
      } catch (FileNotFoundException ex) {
        Logger.getLogger(Opencsv.class.getName()).log(Level.SEVERE, null, ex);
      }
  
    }
  }
  </code></pre>
  
  <p>Cost Class:</p>
  
  <pre><code>public class Cost extends TimerTask{
  
  public void run() {
  Calendar rightNow = Calendar.getInstance();
  Integer hour = rightNow.get(Calendar.HOUR_OF_DAY);
  if (hour==23 ) {
  try {
    URL tariff = new URL("http://www.******.downloadRealtime=true");
              ReadableByteChannel tar = Channels.newChannel(Test.openStream());
              FileOutputStream fos = new FileOutputStream("Test.csv");
              fos.getChannel().transferFrom(tar, 0, 1&lt;&lt;24);
  
   } catch (IOException ex) {
              Logger.getLogger(Cost.class.getName()).log(Level.SEVERE, null, ex);
   } 
    }
  
  
  
  
    else {
  
    }
    }
  </code></pre>