예제 #1
0
        /// <summary>
        /// 取出队头,并放在队尾
        /// 若已取空,从DB中移入
        /// because user buffer class does not have this operation, lstWaitingIDInDB is treated as long type here
        /// on 2011-5-22, it is modified that only lstWaitingID.Count>0, MaxLengthInMem items are removed from DB into memory, so that the performance is enhanced
        /// </summary>
        public long RollQueue()
        {
            //从数据库队列缓存中移入元素
            while (lstWaitingID.Count == 0)
            {
                lstWaitingID = lstWaitingIDInDB.GetFirstValues(iMaxLengthInMem);
            }
            if (lstWaitingID.Count == 0)
            {
                return(0);
            }
            //记录队头
            long lFirstValue = lstWaitingID.First.Value;

            lock (oLock)
            {
                //移入队尾,并从队头移除
                if (lstWaitingID.Count < iMaxLengthInMem && lstWaitingIDInDB.Count == 0)
                {
                    lstWaitingID.AddLast(lFirstValue);
                }
                else
                {
                    lstWaitingIDInDB.Enqueue(lFirstValue);
                }
                lstWaitingID.RemoveFirst();

                //从数据库队列缓存中移入元素
                while (lstWaitingID.Count == 0)
                {
                    lstWaitingID = lstWaitingIDInDB.GetFirstValues(iMaxLengthInMem);
                }
            }
            return(lFirstValue);
        }