⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staxtimedeventqueue.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002                                              *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service.stax;import java.util.TreeSet;import java.util.Comparator;public class STAXTimedEventQueue extends Thread{    public STAXTimedEventQueue()    {        start();    }    public synchronized void end()    {        fComplete = true;        notify();    }    public synchronized void addTimedEvent(STAXTimedEvent timedEvent)    {        fTimedEvents.add(timedEvent);        notify();    }    public synchronized void removeTimedEvent(STAXTimedEvent timedEvent)    {        fTimedEvents.remove(timedEvent);        notify();    }    public void run()    {        synchronized (this)        {            while (true)            {                if (fComplete) return;                if (fTimedEvents.size() == 0)                {                    try                    { wait(); continue; }                    catch (InterruptedException e)                    { /* Do Nothing */ }                }                STAXTimedEvent timedEvent = (STAXTimedEvent)fTimedEvents.first();                long timeout = timedEvent.getNotificationTime() -                    System.currentTimeMillis();                if (timeout <= 0)                {                    timedEvent.getTimedEventListener().timedEventOccurred(                        timedEvent);                    fTimedEvents.remove(timedEvent);                }                else                {                    try                    {                        wait(timeout);                    }                    catch (InterruptedException e)                    { /* Do Nothing */ }                }            }        }    }    // This class is used to sort the conditions in the condition set    class TimedEventComparator implements Comparator    {        public int compare(Object o1, Object o2)        {            STAXTimedEvent t1 = (STAXTimedEvent)o1;            STAXTimedEvent t2 = (STAXTimedEvent)o2;            if (t1.getNotificationTime() == t2.getNotificationTime())            {                if (o1.hashCode() == o2.hashCode()) return 0;                else if (o1.hashCode() < o2.hashCode()) return -1;            }            else if (t1.getNotificationTime() < t2.getNotificationTime())            {                return -1;            }            return 1;        }    }    boolean fComplete = false;    TreeSet fTimedEvents = new TreeSet(new TimedEventComparator());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -