Thread.sleep()永远不会返回 [英] Thread.sleep() Never Returns

查看:361
本文介绍了Thread.sleep()永远不会返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java上遇到奇怪的错误 Thread.sleep()。出于某种原因,当我在某些机器上调用睡眠时,它永远不会返回。我无法弄清楚可能导致此行为的原因。起初,我的错误可能在我的代码中的其他地方,所以我做了最简单的睡眠测试:

I am having an odd error with Thread.sleep() on Java. For some reason, when I call sleep on some machines, it never returns. I can't figure out what could be causing this behaviour. At first, I thgouth the error might be elsewhere in my code, so I made the simplest possible sleep test:

public class SleepTest {
    public static void main (String [] args) {
        System.out.println ("Before sleep...");
        try {
            Thread.sleep (100);
        } catch (InterruptedException e) {
        }
        System.out.println ("After sleep...");
    }
}

在大多数机器上它可以工作,但是在几台机器上我正在远程登录,它在打印语句之间无限期地暂停。我等了半个小时,行为没有变化。显示此错误的计算机是Linux计算机。以下是有关这些机器的一些信息:

On most machines it works, but on several machines which I am remotely logging into, it pauses indefinitely between the print statements. I have waited up to a half an hour with no change in behaviour. The machines that are displaying this error are Linux machines. Here is some information about the machines:

$ uname -a
Linux zone29ea 2.6.32-220.17.1.el6.x86_64 #1 SMP Tue May 15 17:16:46 CDT 2012 x86_64 x86_64 x86_64 GNU/Linux
$ java -version
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.6) (rhel-1.43.1.10.6.el6_2-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

可能导致此行为的原因是什么?

What could be causing this behaviour?

更新

修订版仍然永远不会结束:

Revised version, which still never ends:

public class SleepTest {
    public static void main (String [] args) {
        new Thread () {
            public void run () {
                System.out.println ("Before sleep...");
                try {
                    Thread.sleep (100);
                } catch (InterruptedException e) {
                    e.printStackTrace ();
                }
                System.out.println ("After sleep...");
            }
        }.start();
    }
}


推荐答案

如果你的服务器在Linux下运行,你可能会遇到 Leap第二个错误,它出现在上周末。

if your server is running under Linux, you may be hit by the Leap Second bug which appears last week-end.

这个bug影响Linux内核(线程管理),所以应用程序使用线程(作为JVM,mysql等...)可能会消耗高负载的CPU。

This bug affects the Linux kernel (the Thread management), so application which uses threads (as the JVM, mysql etc...) may consume high load of CPU.

这篇关于Thread.sleep()永远不会返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆