I have a test code for wait(timeout)
.
public static void main(String[] args) throws Exception
{
Runnable r = new Runnable()
{
public void run()
{
while (true)
{
int random = (int)(Math.random() * 10);
synchronized(this)
{
try
{
wait(random);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
System.out.println(random);
}
}
};
new Thread(r).start();
}
But, this seems to to not working properly, ideally it should wait for certain time given by random
method and print it.
But every time it stops after printing several values(random number of times).
Not able to identify what the problem is.