Current Position:Home > ScheduledExecutorService

ScheduledExecutorService

Update:11-30Source: network consolidation
Advertisement
please consider this code sample
service = Executors.newScheduledThreadPool(1);
          final ScheduledFuture<?> timeHandle = service.scheduleWithFixedDelay(new DownloadService(), 0, 10,
                    TimeUnit.SECONDS);
          service.schedule(new Runnable() {
               public void run() {
                    timeHandle.cancel(true);
          }, 365 , TimeUnit.DAYS);     Here I Start the process and this service variable is a global variable and when i want to stop service then i use shutdown method for stop this process
But it does not stop that process properly.can you give me a sample code for stopping that process.
i used This code.
service.shutDown();
What is the problem with this code.

The Best Answer

Advertisement
It sounds like you may be confusing fixed rate with fixed delay, and/or not accounting for the slop in System.currentTimeMillis.
                 Time
          1         2         3         4         5
012345678901234567890123456789012345678901234567890
|-- E0 --||- E1 -|  |E2|      |----E3---||- E4 -|
|-- E0 --|  |- E1 -|  |E2|  |----E3---|  |- E4 -|The first line of executions is fixedRate = 10, so 10 millis from the start of one to the start of the next.
The second line is fixeDelay = 2, so 2 millis from the end of one to the start of the next.
  • Advantages and disadvantages among Timer, ScheduledExecutorService, Thread Update:11-30

    Hi, what are the exact advantages and disadvantages among using Timer, using ScheduledExecutorService and just using Thread (Thread.sleep(...))? For the simple task which needs to poll some values by some interval (the interval is not supposed very a

  • ScheduledExecutorService and Application Module Update:11-30

    I have an Long running job which is submitted from UI, so I used ScheduledExecutorService to execute the task by passing the reference of Application Module. Now the Thread makes some database commits new rows. I have RichPoll which will keep pooling

  • ScheduledExecutorService schedule methods off on Windows XP SP3 Update:11-30

    Running the following code: ScheduledExecutorService schedExec = Executors.newScheduledThreadPool(1); System.out.println("Start: " + new java.util.Date()); ScheduledFuture<?> task = schedExec.scheduleAtFixedRate(new Runnable() { public voi

  • What does scheduledExecutorService.scheduleAtFixedRate() internally do? Update:11-30

    Hi there! Because I'm executing a time critical task every second, I compared several methods to find the best way to ensure that the task is really executed in fixed time steps. After calculation the standard derivation of the error, which is define

  • How to implemented an scheduled service using ScheduledExecutorService Update:11-30

    Hi, everybody I have a case that need retrieve data periodically from server. And I used the ScheduledExecutorService and javafx.concurrent.Service to implemented this case. But the trick thing is that ScheduledExecutorService schedule method aleady

  • ScheduledExecutorService.scheduleWithFixedDelay() stops my System.out.print Update:11-30

    I am using ScheduledExecutorService.scheduleWithFixedDelay(task,delay,period,timeunit) In my task, i have a line of System.out.println("Timer running"). After running the apps for sometimes, the printout will halt but the apps is still running a

  • ScheduledExecutorService.scheduleAtFixedRate executes more than it shouldI Update:11-30

    Hi, I have the following problem, that I hope you can help me resolve (or investigate): ScheduledExecutorService scheduledExecutorService= Executors.newScheduledThreadPool(4, new NamedThreadFactory("MyWorker-")); scheduledExecutorService.schedul

  • ScheduledExecutorService Update:11-30

    please consider this code sample service = Executors.newScheduledThreadPool(1);           final ScheduledFuture<?> timeHandle = service.scheduleWithFixedDelay(new DownloadService(), 0, 10,                     TimeUnit.SECONDS);           service.sch

  • Error 500--Internal Server Error when running a simple ADF application Update:10-11

    Hello, I installed Jdeveloper+ADF (jdevstudio11112install.exe) and i try to run a simple ADF app (which is already running for one of my colleagues) and it boms out with these errors: java.lang.NoSuchMethodError: oracle.jbo.SessionContextManager.remo

  • How to run multiple Thread using Scheduler's in 1.5 Update:10-11

    Hi, I have a scenario, in which I have to run a Thread at every 15 minutes, If the first Thread is not Finished in 15 min then new Thread has to start. Currently I implemeted with java 1.5 schedulers, but the problem is if my first Thread is taking m