What causes scheduled threads to not run in Java?

I developed a small Java application that runs two scheduled threads through a scheduled executor service. On most computers, my application works fine. However, when testing, I came across a computer where my threads do not work as often as they should or not. I have one thread that should start at intervals of 250 ms. It just checks to see if there is anything to read on std if it reads it and executes the command. This thread works sporadically, but not as often as it should. My other thread starts every 5 seconds and just prints something on the screen. It runs once and then never starts again. Here is the code I'm using:

    scheduledThreadManager.scheduleWithFixedDelay(new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                if(inputReader.ready())
                {
                    String command = inputReader.readLine();
                    executeCommand(command);
                }
            }
            catch(IOException e)
            {
                System.out.println(e.toString());
                e.printStackTrace();
            }
        }
    }, 250, 250, TimeUnit.MILLISECONDS);

    scheduledThreadManager.scheduleWithFixedDelay(new Runnable()
    {
        @Override
        public void run()
        {
            System.out.println(idleString);
        }
    }, 0, 5000, TimeUnit.MILLISECONDS);

, . Core2Duo, , , , , . , , . .

+3
2

: " , 250 ", , . scheduleWithFixedDelay, " 250 ". , 100 , 350 , , , .

, .

scheduleAtFixedRate , " X " , :

, ; initialDelay then initialDelay + period, initialDelay + 2 * period, .

scheduleAtFixedRate , , , .

+5

, :

  • , , .

  • , kill -3 (Linux) CTRL-BREAK (Windows), , , . , . :

http://www.0xcafefeed.com/2004/06/of-thread-dumps-and-stack-traces/

+1

Source: https://habr.com/ru/post/1728837/


All Articles