无法,线程控制由jvm决定,程序员是没有办法确切地知道线程的运行情况的。

解决方案 »

  1.   

    做一个boolean的标记,在notify之前将标记置true。
      

  2.   

    JAVA里的线程有很大的不确定性,它个操作平台有很大关系!
      

  3.   

    这种情况的确不一定能够绝对的判断出来,但是一个折衷的方法是
    在synObject.wait(400);的catch InterruptedException语句中,判断
    System.currentTimeMillis() - starttime >= _maxWait如果是,则认为是超时,否则就是
    被唤醒
      

  4.   

    ChDw(米)对我也是这样作的(如果是notify的返回true,如果是时间到了返回false)
    private synchronized boolean P(long waittime)
    {
    if(--curSemaphore<0)
    {
    try
    {
    long curtime=System.currentTimeMillis();
    wait(waittime);
    long delay=System.currentTimeMillis()-curtime;
    if(delay>=waittime)
    {
    if(curSemaphore<maxSemaphore)
    curSemaphore++;
    return false;
    }
    return true;
    }
    catch(InterruptedException e)
    {
    return false;
    }
    }
    return true;
    }
    可是不确定性会带来很大的问题
      

  5.   

    hq1305018(跃强)
    你在notify上设置标志位为true,在什么时候恢复这个标志位了(是在wait等待返回过后吗?)