kaffe Java 解释器语言,源码,Java的子集系统,开放源代码

源代码在线查看: waittest.java

软件大小: 8683 K
上传用户: liangshuo800
关键词: Java kaffe 语言 源码
下载地址: 免注册下载 普通下载 VIP

相关代码

								class WaitTest				    implements Runnable				{				    static final long TOLERANCE = 100;								    private final Object waiter;				    				    WaitTest(Object waiter)				    {					this.waiter = waiter;				    }				    				    public void run()				    {					synchronized( this.waiter )					{					    try { Thread.sleep(500); } catch(InterruptedException e) { }					    this.waiter.notifyAll();					}				    }								    public static void main(String args[])					throws Exception				    {					Object waiter = new Object();					long start, actual, end;										synchronized( waiter )					{					    final long time = 500;					    					    start = System.currentTimeMillis();					    waiter.wait(time);					    end = System.currentTimeMillis();					    actual = end - start;					    if( (actual > (time - TOLERANCE)) &&						(actual < (time + TOLERANCE)) )					    {						System.out.println("Okie");					    }					    else					    {						System.out.println("Fail");					    }					}									new Thread(new WaitTest(waiter)).start();					synchronized( waiter )					{					    final long time = 500;					    					    start = System.currentTimeMillis();					    waiter.wait(Long.MAX_VALUE);					    end = System.currentTimeMillis();					    actual = end - start;					    if( (actual > (time - TOLERANCE)) &&						(actual < (time + TOLERANCE)) )					    {						System.out.println("Okie");					    }					    else					    {						System.out.println("Fail "								   + end								   + " - "								   + start								   + " = "								   + actual);					    }					}								    }				}								/* Expected Output:				Okie				Okie				*/							

相关资源