Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6639183

Scheduling large negative delay hangs entire ScheduledExecutor

    XMLWordPrintable

    Details

      Backports

        Description

        type: bug
        product: j2se
        sub-cat: java.util.*
        release: Java 6
        O/S: Windows XP

        Synopsis: Scheduling large negative delay hangs entire ScheduledExecutor

        Full O/S version: Microsoft Windows XP [Version 5.1.2600]
        java -version:

        both

        java version "1.5.0_12"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
        Java HotSpot(TM) Client VM (build 1.5.0_12-b04, mixed mode)

        and

        java version "1.6.0_03"
        Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
        Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)


        Description:

        Scheduling something with a very large negative delay (using TimeUnit.MILLISECONDS) blocks the scheduled executor from running anything. Other than perhaps relative ordering, negative delay (no matter how large) is effectively the same as zero delay and the scheduled item ought to be eligible to run immediately.

        Frequency: always

        Regression: no

        Steps to reproduce:

        import java.util.concurrent.ScheduledThreadPoolExecutor;
        import java.util.concurrent.TimeUnit;

        public class ScheduleBug {
            public static void main(String[] args) {
                ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);

                exec.schedule(new Op("one"), -1000, TimeUnit.MILLISECONDS);
                exec.schedule(new Op("two"), -100, TimeUnit.MILLISECONDS);
                exec.schedule(new Op("three"), -10, TimeUnit.MILLISECONDS);
                exec.schedule(new Op("four"), 0, TimeUnit.MILLISECONDS);
                exec.schedule(new Op("five"), 1000, TimeUnit.MILLISECONDS);
                exec.schedule(new Op("six"), 5000, TimeUnit.MILLISECONDS);
                exec.schedule(new Runnable() {
                    public void run() { System.exit(0); }
                }, 10000, TimeUnit.MILLISECONDS);
            }


            static class Op implements Runnable {
                private final String m_message;

                public Op(String message)
                { m_message = message; }

                public void run() {
                    System.out.println(m_message);
                    System.out.flush();
                }
            }
        }

        produces the following output as expected (after 10-15s):
        one
        two
        three
        four
        five
        six


        However, change the first schedule line from
                exec.schedule(new Op("one"), -1000, TimeUnit.MILLISECONDS);
        to
                exec.schedule(new Op("one"), Long.MIN_VALUE, TimeUnit.MILLISECONDS);

        and the program will hang for hours with no output at all.

        problems:

        1) should be exact same output.
        2) Even if underflow were documented / specified behavior, scheduling op "one" far in the future should NOT prevent other ops from running right away

        severity: some progress possible

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                martin Martin Buchholz
                Reporter:
                elarsen Erik Larsen (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: