Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:24:51+00:00 2026-05-28T14:24:51+00:00

I have a question relating to the timer function. I have managed to find

  • 0

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?

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();
      }

Opencsv class file:

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);
    }

  }
}

Cost Class:

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<<24);

 } catch (IOException ex) {
            Logger.getLogger(Cost.class.getName()).log(Level.SEVERE, null, ex);
 } 
  }




  else {

  }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:24:52+00:00Added an answer on May 28, 2026 at 2:24 pm

    I think your bug is that you never call Cost‘s run() method, you are not just overriding it, you are hiding it. Try something like this:

    timer.scheduleAtFixedRate(new Cost() {
      @Override
        public void run() {
    
        super.run();  //Added this call to Cost's original method.
    
        new Thread(new Runnable() {
            public void run() {
              //your code still here
            }
          }).start();
      }
    

    Although, as others point out, you should look into the Executor Service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this question relating to Lucene. I have a form and I get
I have a question relating to alignment in C/C++. In Determining the alignment of
I am hoping someone can help me with a question i have relating to
I have question regarding the use of function parameters. In the past I have
I have question concerning a function I created. I would like to show the
I know this may not be exactly a coder question, but I feel it
I have a question relating programming and english language both: Whether to use third
I have a question relating to the usage of this. Suppose I have two
Ok, I have a question relating to an issue I've previously had. I know
I have a question out of curiosity relating to checking for memory leaks. Being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.