List of usage examples for java.util.concurrent ConcurrentLinkedQueue ConcurrentLinkedQueue
public ConcurrentLinkedQueue()
From source file:org.netxilia.server.service.user.impl.WindowProcessorImpl.java
private void addWindow(Window window, ISheet sheet) throws StorageException { Collection<Window> windowList = windowsBySheet.get(sheet.getFullName()); if (windowList == null) { Collection<Window> newWindowList = new ConcurrentLinkedQueue<Window>(); windowList = windowsBySheet.putIfAbsent(sheet.getFullName(), newWindowList); if (windowList == null) { windowList = newWindowList;//www .ja va 2 s . c o m } } windowList.add(window); // add listeners for sheet sheet.addListener(this); }
From source file:org.sonar.server.db.migrations.v36.Referentials.java
private Queue<long[]> initGroupOfViolationIds(Database database) throws SQLException { Connection connection = database.getDataSource().getConnection(); Statement stmt = null;/*from w ww . j a va 2s. c om*/ ResultSet rs = null; try { connection.setAutoCommit(false); stmt = connection.createStatement(); stmt.setFetchSize(10000); rs = stmt.executeQuery("select id from rule_failures"); Queue<long[]> queue = new ConcurrentLinkedQueue<long[]>(); totalViolations = 0; long[] block = new long[VIOLATION_GROUP_SIZE]; int cursor = 0; while (rs.next()) { block[cursor] = rs.getLong(1); cursor++; totalViolations++; if (cursor == VIOLATION_GROUP_SIZE) { queue.add(block); block = new long[VIOLATION_GROUP_SIZE]; cursor = 0; } } if (cursor > 0) { queue.add(block); } return queue; } finally { DbUtils.closeQuietly(connection, stmt, rs); } }
From source file:mcnutty.music.get.ProcessQueue.java
void save_queue() { try (PrintWriter file = new PrintWriter("queue.json")) { ConcurrentLinkedQueue<QueueItem> queue_dump = new ConcurrentLinkedQueue<>(); QueueItem last_item = new QueueItem(); for (QueueItem item : bucket_played) last_item = item;//from w ww . ja v a2 s. c o m queue_dump.add(last_item); queue_dump.addAll(bucket_queue); file.println(json_array_list(queue_dump).toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:org.sonar.server.db.migrations.violation.Referentials.java
private Queue<long[]> initGroupOfViolationIds(Database database) throws SQLException { Connection connection = database.getDataSource().getConnection(); Statement stmt = null;/*from ww w . j a v a 2 s . co m*/ ResultSet rs = null; try { connection.setAutoCommit(false); stmt = connection.createStatement(); stmt.setFetchSize(10000); rs = stmt.executeQuery("select id from rule_failures"); ConcurrentLinkedQueue<long[]> queue = new ConcurrentLinkedQueue<long[]>(); totalViolations = 0; long[] block = new long[VIOLATION_GROUP_SIZE]; int cursor = 0; while (rs.next()) { block[cursor++] = rs.getLong(1); totalViolations++; if (cursor == VIOLATION_GROUP_SIZE) { queue.add(block); block = new long[VIOLATION_GROUP_SIZE]; cursor = 0; } } if (cursor > 0) { queue.add(block); } return queue; } finally { DbUtils.closeQuietly(connection, stmt, rs); } }
From source file:ws.salient.aws.dynamodb.DynamoDBStore.java
public DynamoDBStore(DynamoDB dynamodb, AWSKMS kms, ObjectMapper json, ExecutorService putItemExecutor) { this.kms = kms; this.dynamodb = dynamodb; this.json = json; this.transformation = "AES/CBC/PKCS5Padding"; this.putItemExecutor = putItemExecutor; sessionsToPut = new ConcurrentLinkedQueue(); eventsToPut = new ConcurrentLinkedQueue(); }
From source file:org.syncany.tests.integration.scenarios.Issue429ScenarioTest.java
@Ignore public void testSameFileDifferentNameFuzzy() throws Exception { for (int seed = 0; seed < 1000; seed++) { LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil .createTestLocalConnection(); TestClient clientA = new TestClient("A", testConnection); TestClient clientB = new TestClient("B", testConnection); Random randomA = new Random(2 * seed); Random randomB = new Random(2 * seed + 1); Queue<String> queue = new ConcurrentLinkedQueue<>(); activeThread A = new activeThread(randomA, clientA, queue); activeThread B = new activeThread(randomB, clientB, queue); Thread AThread = new Thread(A, "A"); Thread BThread = new Thread(B, "B"); try {// w w w. j a v a2 s . c o m AThread.start(); BThread.start(); // int actionsA = -1; // int actionsB = -1; for (int i = 0; i < 50; i++) { TestClient clientC = new TestClient("C", testConnection); clientC.down(); if (!AThread.isAlive() || !BThread.isAlive()) { throw new RuntimeException("One of the threads died"); } FileUtils.deleteDirectory(clientC.getLocalFile("")); Thread.sleep(2000); } AThread.interrupt(); BThread.interrupt(); } catch (Exception e) { logger.log(Level.INFO, "Queue:" + queue.toString()); logger.log(Level.INFO, "Something went wrong at seed: " + seed); throw e; } clientA.deleteTestData(); clientB.deleteTestData(); } }
From source file:com.netflix.curator.framework.recipes.locks.TestReaper.java
@Test public void testSparseUseNoReap() throws Exception { final int THRESHOLD = 3000; Timing timing = new Timing(); Reaper reaper = null;//from w ww .j a va2 s. c o m Future<Void> watcher = null; CuratorFramework client = makeClient(timing, null); try { client.start(); client.create().creatingParentsIfNeeded().forPath("/one/two/three"); Assert.assertNotNull(client.checkExists().forPath("/one/two/three")); final Queue<Reaper.PathHolder> holders = new ConcurrentLinkedQueue<Reaper.PathHolder>(); final ExecutorService pool = Executors.newCachedThreadPool(); ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1) { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { final Reaper.PathHolder pathHolder = (Reaper.PathHolder) command; holders.add(pathHolder); final ScheduledFuture<?> f = super.schedule(command, delay, unit); pool.submit(new Callable<Void>() { @Override public Void call() throws Exception { f.get(); holders.remove(pathHolder); return null; } }); return f; } }; reaper = new Reaper(client, service, THRESHOLD); reaper.start(); reaper.addPath("/one/two/three"); long start = System.currentTimeMillis(); boolean emptyCountIsCorrect = false; while (((System.currentTimeMillis() - start) < timing.forWaiting().milliseconds()) && !emptyCountIsCorrect) // need to loop as the Holder can go in/out of the Reaper's DelayQueue { for (Reaper.PathHolder holder : holders) { if (holder.path.endsWith("/one/two/three")) { emptyCountIsCorrect = (holder.emptyCount > 0); break; } } Thread.sleep(1); } Assert.assertTrue(emptyCountIsCorrect); client.create().forPath("/one/two/three/foo"); Thread.sleep(2 * (THRESHOLD / Reaper.EMPTY_COUNT_THRESHOLD)); Assert.assertNotNull(client.checkExists().forPath("/one/two/three")); client.delete().forPath("/one/two/three/foo"); Thread.sleep(THRESHOLD); timing.sleepABit(); Assert.assertNull(client.checkExists().forPath("/one/two/three")); } finally { if (watcher != null) { watcher.cancel(true); } IOUtils.closeQuietly(reaper); IOUtils.closeQuietly(client); } }
From source file:org.ramidore.logic.system.GuildBattleLogic.java
/** * ./*from ww w. ja va 2 s . c om*/ */ public GuildBattleLogic() { logDataQ = new ConcurrentLinkedQueue<GvLogTable>(); nameSet = new HashSet<String>(); killDeathNameSet = new HashSet<String>(); logDataQ.clear(); dupChecker = new DuplicateChecker(); pointChecker = new PointChecker(); }
From source file:de.hybris.platform.jdbcwrapper.ConnectionPoolTest.java
private void doTestMultithreadedAccess(final int RUN_SECONDS, final int THREADS, final int PERCENT_NO_TX, final int PERCENT_TX_ROLLBACK, final boolean useInterrupt, final boolean sendDummyStatement) { HybrisDataSource dataSource = null;//from w w w.j a v a 2 s. com LOG.info("--- test multithreaded access to connection pool duration:" + RUN_SECONDS + "s threads:" + THREADS + " nonTx:" + PERCENT_NO_TX + "% rollback:" + PERCENT_TX_ROLLBACK + "% interrupt:" + useInterrupt + "-----------------------------------"); try { final Collection<TestConnectionImpl> allConnections = new ConcurrentLinkedQueue<TestConnectionImpl>(); final AtomicLong rollbackCounter = new AtomicLong(0); final AtomicLong connectionCounter = new AtomicLong(0); final AtomicBoolean finished = new AtomicBoolean(false); dataSource = createDataSource(Registry.getCurrentTenantNoFallback(), allConnections, connectionCounter, false, false); assertEquals(0, dataSource.getNumInUse()); assertEquals(1, dataSource.getNumPhysicalOpen()); assertEquals(1, dataSource.getMaxInUse()); assertEquals(1, dataSource.getMaxPhysicalOpen()); final int maxConnections = dataSource.getMaxAllowedPhysicalOpen(); final String runId = "[" + RUN_SECONDS + "|" + THREADS + "|" + PERCENT_NO_TX + "|" + PERCENT_TX_ROLLBACK + "|" + useInterrupt + "]"; final Runnable runnable = new ContinuousAccessRunnable(dataSource, PERCENT_NO_TX, PERCENT_TX_ROLLBACK, rollbackCounter, finished, runId, sendDummyStatement); final TestThreadsHolder threadsHolder = new TestThreadsHolder(THREADS, runnable) { @Override public void stopAll() { if (useInterrupt) { super.stopAll(); } else { finished.set(true); } } }; threadsHolder.startAll(); waitDuration(RUN_SECONDS, maxConnections, dataSource, allConnections); threadsHolder.stopAll(); final boolean allStoppedNormal = threadsHolder.waitForAll(30, TimeUnit.SECONDS); if (!allStoppedNormal) { // try fallback method finished.set(true); final boolean allStoppedFallback = threadsHolder.waitForAll(10, TimeUnit.SECONDS); if (allStoppedFallback) { LOG.error("Threads did not stop normally but only after using boolean flag!"); } else { fail("db connection test threads did not stop correctly even after fallback method"); } } // kill data source dataSource.destroy(); assertTrue(dataSource.getConnectionPool().isPoolClosed()); assertTrue(waitForAllInactive(dataSource.getConnectionPool(), 10, TimeUnit.SECONDS)); if (PERCENT_TX_ROLLBACK > 0) { assertTrue(rollbackCounter.get() > 0); } final long maxAllowedConnections = maxConnections + rollbackCounter.get(); final Stats stats = getStats(allConnections); LOG.info(// "max connections :" + maxConnections + "\n" + // "rollbacks :" + rollbackCounter.get() + "\n" + // "real connections :" + connectionCounter.get() + "\n" + // "closed:" + stats.closed + "\n" + // "open:" + stats.open + "\n" + // "borrowed :" + stats.borrowed + "\n" + // "returned :" + stats.returned + "\n" + // "invalidated :" + stats.invalidated + "\n"); // we cannot be sure since not each rollbacked connections *must* be re-created assertTrue( "handed out more than max connections (got:" + connectionCounter.get() + " > max:" + maxAllowedConnections + ")", // connectionCounter.get() <= maxAllowedConnections); assertEquals("still got " + stats.borrowed + "borrowed connections", 0, stats.borrowed); assertEquals( "connection count mismatch - total:" + connectionCounter.get() + " <> " + (stats.returned + stats.invalidated) + " (returned:" + stats.returned + " + invalidated:" + stats.invalidated + ")", // connectionCounter.get(), stats.returned + stats.invalidated); // make sure all connections have been finally closed assertEquals( "data source " + dataSource + "still got " + dataSource.getNumInUse() + " connections in use", // 0, dataSource.getNumInUse()); assertEquals( "data source " + dataSource + "still got " + dataSource.getNumPhysicalOpen() + " physical connections open (despite none are in use)", // 0, dataSource.getNumPhysicalOpen()); assertTrue( "data source " + dataSource + " had more than max allowed connections (max:" + maxConnections + ", max in use:" + dataSource.getMaxInUse() + ")", // maxConnections >= dataSource.getMaxInUse()); assertTrue( "data source " + dataSource + " had more than max allowed physical connections (max:" + maxConnections + ", max physical in use:" + dataSource.getMaxPhysicalOpen() + ")", // maxConnections >= dataSource.getMaxPhysicalOpen()); } finally { destroyDataSource(dataSource); } }
From source file:com.netflix.discovery.shared.Applications.java
/** * Create a new, empty Eureka application list. */ public Applications() { this.applications = new ConcurrentLinkedQueue<Application>(); }