cat_mucius: (Default)
cat_mucius ([personal profile] cat_mucius) wrote2015-11-10 02:17 am
Entry tags:

(no subject)

Вот какой бы вывод вы ожидали увидеть, запустив такую простенькую java-програмку на винде?
public static void main(String[] args)
{
    long first;
    long next;
				
    first = System.currentTimeMillis();
    while (true)
    {
        next = System.currentTimeMillis();
        if (first != next)
            break;
    }
				
    System.out.println("Difference: " + (next - first));
}


А такую?
public static void main(String[] args)
{
    long first;
    long next;
		
    Thread t = new Thread()
    {
        public void run()
        {
            try
            {
                Thread.sleep(Integer.MAX_VALUE);
            } catch (InterruptedException e) {}
        }
    };
    t.start();
		
    first = System.currentTimeMillis();
    while (true)
    {
        next = System.currentTimeMillis();
        if (first != next)
            break;
    }
				
    System.out.println("Difference: " + (next - first));
    t.interrupt();
}


Жизнь, натурально, прекрасна и удивительна.

Post a comment in response:

You may post here only if cat_mucius has given you access; posting by non-Access List accounts has been disabled.
If you don't have an account you can create one now.
No Subject Icon Selected
More info about formatting