Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a very strange Java issue which occurs only on a particular computer running Ubuntu.

When I call the wait(timeout) function it always waits exactly 1000ms less than the time out amount I specify. The sleep() function behaves even more bizarrely - it sleeps an amount of time that seems to have nothing to do with that specified.

I have written some test code (listed below) and run on two computers both with Ubuntu installed. In one which is running 11.04 it behaves exactly as expected. On other computer which is running 10.04, I get the problems described above.

Surely its not because its running an older version? Both are 64bit architectures. I am stumped as to what could be causing such strange behavior.

Any help much appreciated

Des

public class Test {
public static void main(String args[])
    throws Exception
{
    Integer timeout = new Integer(args[0]);
    for(;;)
    {
        long start = System.currentTimeMillis();
        System.out.println("Waiting: " + timeout);
        synchronized(timeout)
        {
            try
            {
                timeout.wait(timeout);
                // Uncomment below to try sleep option
                // Thread.currentThread().sleep(timeout);
            }
            catch(InterruptedException e)
            {
            }
        }
        System.out.println("Time: " + (System.currentTimeMillis() - start));
        System.in.read();
    }
} }
share|improve this question

closed as off topic by fossfreedom Feb 2 '13 at 10:15

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Is this still an issue? –  hexafraction Aug 29 '12 at 12:25

Browse other questions tagged or ask your own question.