I was following along to the following tutorial - Derek Banas Java tutorial 18 - Threads pt2 and as I decided to go over his tutorial series by following along in notepad++ and compiling with the command line, so that I can experiment and test things I'm unsure about, I figured the problem I encountered must be an error in the my typing. However, after skipping to the second stage, which is when I download his commented source code and read over it in eclipse, I noticed his code was identical. I then opened my code in eclipse and got the same error I was getting in the command line, until I pasted his line above it. Though identical the error disappeared?! when I removed the line again the code went back to its broken state. I'm totally confused.

Below is my code:

import java.util.concurrent.ScheduledThreadPoolExecutor;

import java.util.concurrent.TimeUnit;

public class JavaLesson18t{

  public static void main(String[] args){

    addThreadsToPool();

  }

  public static void addThreadsToPool(){

    ScheduledThreadPoolExecutor eventPool = new ScheduledThreadPoolExecutor(5);



    eventPool.scheduleAtFixedRate(new CheckSystemTime(), 0, 2, SECONDS);
    eventPool.scheduleAtFixedRate(new PerformSystemCheck("Mail"), 5,5,SECONDS);
    eventPool.scheduleAtFixedRate(new PerformSystemCheck("Calendar"), 0, 2, SECONDS);

    System.out.println("Number of Threads: " + Thread.activeCount());

  }

}

And below is the line that when pasted into this code in eclipse, magically fixes the problem..

eventPool.scheduleAtFixedRate(new CheckSystemTime(), 0, 2, SECONDS);

Please advise, I really don't know whats going on here..

p.s it only fixes it in eclipse, the code is still broken in notepad++

right, sorry! in eclipse it says "SECONDS cannot be resolved to a variable"

the terminal outputs:

JavaLesson18.java:18: error: cannot find symbol
    eventPool.scheduleAtFixedRate(new CheckSystemTime(), , 2, SECONDS);

  symbol:   variable SECONDS
  location: class JavaLesson18
JavaLesson18.java:19: error: cannot find symbol
    eventPool.scheduleAtFixedRate(new PerformSystemCheck("Mail"), 5, 5,SECONDS);

and so on..

Try
TimeUnit.SECONDS
or chnage the import to
import static java.util.concurrent.TimeUnit.*;

Edited 2 Years Ago by JamesCherrill

I had tried the first before, but it didn;t work.

but making the import static fixed it! Had never seen a static import before and overlooked it. still dont get why the thing started working in eclipse when I pasted the exact same line from the source code though, makes no sense to me.

This question has already been answered. Start a new discussion instead.