Java Code Examples for java.util.concurrent.ConcurrentLinkedQueue#remove()

The following examples show how to use java.util.concurrent.ConcurrentLinkedQueue#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClearThread.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    for (Entry<String, Integer> e : drpcService.getIdToStart().entrySet()) {
        if (TimeUtils.time_delta(e.getValue()) > REQUEST_TIMEOUT_SECS) {
            String id = e.getKey();

            LOG.warn("DRPC request timed out, id: {} start at {}", id, e.getValue());
            ConcurrentLinkedQueue<DRPCRequest> queue = drpcService.acquireQueue(drpcService.getIdToFunction().get(id));
            queue.remove(drpcService.getIdToRequest().get(id)); //remove timeout request
            Semaphore s = drpcService.getIdToSem().get(id);
            if (s != null) {
                s.release();
            }
            drpcService.cleanup(id);
            LOG.info("Clear request " + id);
        }
    }
    JStormUtils.sleepMs(10);
}
 
Example 2
Source File: Okexv3WebSocketExchange.java    From GOAi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void noDepth(String pushId) {
    WebSocketInfo info = Okexv3WebSocketExchange.CONSUMERS.get(pushId);
    if (null != info) {
        String symbol = info.getSymbol();
        ConcurrentLinkedQueue<WebSocketInfo<Depth>> list = Okexv3WebSocketExchange.DEPTH
                .getOrDefault(symbol, null);
        if (null != list) {
            if (list.size() <= 1) {
                // 这是最后一个订阅,需要取消订阅
                Okexv3WebSocketClient client = Okexv3WebSocketExchange.CLIENTS.get(symbol);
                if (null != client) {
                    client.noDepth();
                }
            }
            list.remove(info);
        }
        Okexv3WebSocketExchange.CONSUMERS.remove(pushId);
    }
}
 
Example 3
Source File: Okexv3WebSocketExchange.java    From GOAi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void noTrades(String pushId) {
    WebSocketInfo info = Okexv3WebSocketExchange.CONSUMERS.get(pushId);
    if (null != info) {
        String symbol = info.getSymbol();
        ConcurrentLinkedQueue<WebSocketInfo<Trades>> list = Okexv3WebSocketExchange.TRADES
                .getOrDefault(symbol, null);
        if (null != list) {
            if (list.size() <= 1) {
                // 这是最后一个订阅,需要取消订阅
                Okexv3WebSocketClient client = Okexv3WebSocketExchange.CLIENTS.get(symbol);
                if (null != client) {
                    client.noTrades();
                }
            }
            list.remove(info);
        }
        Okexv3WebSocketExchange.CONSUMERS.remove(pushId);
    }
}
 
Example 4
Source File: BinlogWorker.java    From binlake with Apache License 2.0 6 votes vote down vote up
/**
 * 如果未获取到锁 可能有冲突 立马返回 等待下次执行
 *
 * @param logPositions binlog 位置队列 {线程安全}
 * @param rms          需要被删除的 对象
 */
private void removeQueueWithLock(ConcurrentLinkedQueue<LogPosition> logPositions,
                                 List<LogPosition> rms) {
    if (lock.tryLock()) {
        try {
            // 删除队列 需要有锁防止写冲突 注意这里的log pos 与 work.removeLogPosition() 为不同属性
            for (LogPosition lp : rms) {
                logPositions.remove(lp);
                keepDump();
            }
        } finally {
            lock.unlock();
        }
    }
    rms.clear();
}
 
Example 5
Source File: Okexv3WebSocketExchange.java    From GOAi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void noTicker(String pushId) {
    WebSocketInfo info = Okexv3WebSocketExchange.CONSUMERS.get(pushId);
    if (null != info) {
        String symbol = info.getSymbol();
        ConcurrentLinkedQueue<WebSocketInfo<Ticker>> list = Okexv3WebSocketExchange.TICKERS
                .getOrDefault(symbol, null);
        if (null != list) {
            if (list.size() <= 1) {
                // 这是最后一个订阅,需要取消订阅
                Okexv3WebSocketClient client = Okexv3WebSocketExchange.CLIENTS.get(symbol);
                if (null != client) {
                    client.noTicker();
                }
            }
            list.remove(info);
        }
        Okexv3WebSocketExchange.CONSUMERS.remove(pushId);
    }
}
 
Example 6
Source File: FileUtil.java    From Blog with Apache License 2.0 6 votes vote down vote up
/**
  * 获取可用的文件保存路径
  * 当所有路径文件夹单位数都超过FolderSize时,返回null
  *
  * @return
  */
 public String getSavePath() {

     ConcurrentLinkedQueue<File> availablePath = ImgUploadConfig.getAvailablePath();
     Iterator<File> iterator = availablePath.iterator();
    
     while (iterator.hasNext()) { 
File file = iterator.next();
         if (file.listFiles().length < imgUploadConfig.getFolderSize()) {
             return file.getPath();
         } else {
             availablePath.remove(file);
         }
     }
     return null;
 }
 
Example 7
Source File: RemoveLeak.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    int i = 0;
    // Without bug fix, OutOfMemoryError was observed at iteration 65120
    int iterations = 10 * 65120;
    try {
        ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
        queue.add(0L);
        while (i++ < iterations) {
            queue.add(1L);
            queue.remove(1L);
        }
    } catch (Error t) {
        System.err.printf("failed at iteration %d/%d%n", i, iterations);
        throw t;
    }
}
 
Example 8
Source File: RemoveLeak.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    int i = 0;
    // Without bug fix, OutOfMemoryError was observed at iteration 65120
    int iterations = 10 * 65120;
    try {
        ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
        queue.add(0L);
        while (i++ < iterations) {
            queue.add(1L);
            queue.remove(1L);
        }
    } catch (Error t) {
        System.err.printf("failed at iteration %d/%d%n", i, iterations);
        throw t;
    }
}
 
Example 9
Source File: SnackBar.java    From SnackBar with Apache License 2.0 6 votes vote down vote up
/**
 * Cleans up the {@link SnackBarItem} and the {@link Activity} it is tied to
 *
 * @param activity     The {@link Activity} tied to the {@link SnackBarItem}
 * @param snackBarItem The {@link SnackBarItem} to clean up
 */
public void disposeSnackBar(Activity activity, SnackBarItem snackBarItem) {
    ConcurrentLinkedQueue<SnackBarItem> list = mQueue.get(activity);

    if (list != null) {
        list.remove(snackBarItem);

        if (list.peek() == null) {
            mQueue.remove(activity);
            mIsShowingSnackBar = false;
        } else if (!mIsCanceling) {
            mIsShowingSnackBar = true;
            list.peek().show();
        }
    }
}
 
Example 10
Source File: ConcurrentLinkedQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * retainAll(c) retains only those elements of c and reports true if change
 */
public void testRetainAll() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    ConcurrentLinkedQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
Example 11
Source File: RemoveLeak.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    int i = 0;
    // Without bug fix, OutOfMemoryError was observed at iteration 65120
    int iterations = 10 * 65120;
    try {
        ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
        queue.add(0L);
        while (i++ < iterations) {
            queue.add(1L);
            queue.remove(1L);
        }
    } catch (Error t) {
        System.err.printf("failed at iteration %d/%d%n", i, iterations);
        throw t;
    }
}
 
Example 12
Source File: RemoveLeak.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    int i = 0;
    // Without bug fix, OutOfMemoryError was observed at iteration 65120
    int iterations = 10 * 65120;
    try {
        ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
        queue.add(0L);
        while (i++ < iterations) {
            queue.add(1L);
            queue.remove(1L);
        }
    } catch (Error t) {
        System.err.printf("failed at iteration %d/%d%n", i, iterations);
        throw t;
    }
}
 
Example 13
Source File: BeamEnumerableConverter.java    From beam with Apache License 2.0 6 votes vote down vote up
private static Enumerable<Object> limitCollect(PipelineOptions options, BeamRelNode node) {
  long id = options.getOptionsId();
  ConcurrentLinkedQueue<Row> values = new ConcurrentLinkedQueue<>();

  checkArgument(
      options
          .getRunner()
          .getCanonicalName()
          .equals("org.apache.beam.runners.direct.DirectRunner"),
      "SELECT without INSERT is only supported in DirectRunner in SQL Shell.");

  int limitCount = getLimitCount(node);

  Collector.globalValues.put(id, values);
  limitRun(options, node, new Collector(), values, limitCount);
  Collector.globalValues.remove(id);

  // remove extra retrieved values
  while (values.size() > limitCount) {
    values.remove();
  }

  return Linq4j.asEnumerable(rowToAvaticaAndUnboxValues(values));
}
 
Example 14
Source File: ConcurrentLinkedQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    assertTrue(q.isEmpty());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
Example 15
Source File: ConcurrentLinkedQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
Example 16
Source File: ConcurrentLinkedQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        ConcurrentLinkedQueue q = populatedQueue(SIZE);
        ConcurrentLinkedQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.remove());
            assertFalse(q.contains(x));
        }
    }
}
 
Example 17
Source File: PhysicalDatasource.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
private void checkIfNeedHeartBeat(
		LinkedList<BackendConnection> heartBeatCons, ConQueue queue,
		ConcurrentLinkedQueue<BackendConnection> checkLis,
		long hearBeatTime, long hearBeatTime2) {
	int maxConsInOneCheck = 10;
	Iterator<BackendConnection> checkListItor = checkLis.iterator();
	while (checkListItor.hasNext()) {
		BackendConnection con = checkListItor.next();
		if (con.isClosedOrQuit()) {
			checkListItor.remove();
			continue;
		}
		if (validSchema(con.getSchema())) {
			if (con.getLastTime() < hearBeatTime
					&& heartBeatCons.size() < maxConsInOneCheck) {
				if(checkLis.remove(con)) { 
					//如果移除成功,则放入到心跳连接中,如果移除失败,说明该连接已经被其他线程使用,忽略本次心跳检测
					con.setBorrowed(true);
					heartBeatCons.add(con);
				}
			}
		} else if (con.getLastTime() < hearBeatTime2) {
			// not valid schema conntion should close for idle
			// exceed 2*conHeartBeatPeriod
			// 同样,这里也需要先移除,避免被业务连接
			if(checkLis.remove(con)) { 
				con.close(" heart beate idle ");
			}
		}

	}

}
 
Example 18
Source File: AbstractPool.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected LinkedList<BackendConnection> getNeedHeartbeatCons(
		ConcurrentLinkedQueue<BackendConnection> checkLis, long heartbeatTime, long closeTime) {
	
	int maxConsInOneCheck = 10;
	LinkedList<BackendConnection> heartbeatCons = new LinkedList<BackendConnection>();
	
	Iterator<BackendConnection> checkListItor = checkLis.iterator();
	while (checkListItor.hasNext()) {
		BackendConnection con = checkListItor.next();
		if ( con.isClosed() ) {
			checkListItor.remove();
			continue;
		}
		
		// 关闭 闲置过久的 connection
		if (con.getLastTime() < closeTime) {
			if(checkLis.remove(con)) { 
				con.close("heartbeate idle close ");
				continue;
			}
		}
		
		// 提取需要做心跳检测的 connection
		if (con.getLastTime() < heartbeatTime && heartbeatCons.size() < maxConsInOneCheck) {
			// 如果移除失败,说明该连接已经被其他线程使用
			if(checkLis.remove(con)) { 
				con.setBorrowed(true);
				heartbeatCons.add(con);
			}
		} 
	}
	
	return heartbeatCons;
}
 
Example 19
Source File: ConcurrentLinkedQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
Example 20
Source File: BackendChannelContextCache.java    From Mycat-Balance with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param backendServer
 * @param backendChannelContext
 * @return
 */
public static boolean remove(ChannelContext backendChannelContext)
{
	BackendServerConf backendServer = BackendExt.getBackendServer(backendChannelContext);
	ConcurrentLinkedQueue<ChannelContext> queue = queueMap.get(backendServer);
	return queue.remove(backendChannelContext);
}