List of usage examples for java.util.concurrent.atomic AtomicLong set
public final void set(long newValue)
From source file:Main.java
public static void main(String[] argv) { AtomicLong nextId = new AtomicLong(); nextId.set(12312L); System.out.println(nextId.longValue()); }
From source file:com.linkedin.pinot.tools.perf.QueryRunner.java
private static void reportAndClearStatistics(AtomicInteger numQueriesExecuted, AtomicLong totalBrokerTime, AtomicLong totalClientTime, List<Statistics> statisticsList) { numQueriesExecuted.set(0);//from www . j a v a 2 s . com totalBrokerTime.set(0L); totalClientTime.set(0L); for (Statistics statistics : statisticsList) { statistics.report(); statistics.clear(); } }
From source file:org.tros.utils.Random.java
/** * Reset the specified counter to the specified value. * * @param c//from w w w .j a v a 2 s . c om * @param value */ public synchronized static void reset(Class<?> c, long value) { String key = DEFAULT_KEY; switch (_incrementType) { case useClass: key = c.getName(); break; case usePackage: key = c.getPackage().getName(); break; } if (!COUNTERS.containsKey(key)) { COUNTERS.put(key, new AtomicLong(1)); } AtomicLong l = COUNTERS.get(key); l.set(value + 1); }
From source file:org.apache.hadoop.hbase.client.metrics.ScanMetrics.java
public void setCounter(String counterName, long value) { AtomicLong c = this.counters.get(counterName); if (c != null) { c.set(value); }/*from w w w . j a v a 2s .c o m*/ }
From source file:com.jivesoftware.os.amza.service.storage.WALStorage.java
private static void minimize(AtomicLong existing, long value) { long existingValue = existing.get(); if (existingValue == -1 || value < existingValue) { existing.set(value); }/* www . j a v a2s.c o m*/ }
From source file:com.aol.advertising.qiao.management.metrics.StatisticsStore.java
@Override @ManagedOperation(description = "Reset counters") public void resetCounters() { for (AtomicLong v : stats.values()) { v.set(0); }//from w w w . ja v a 2s . co m }
From source file:ubicrypt.core.UtilsTest.java
private void write(final int size) throws InterruptedException, IOException { final Path target = Paths.get(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final byte[] bytes = new byte[size]; new Random().nextBytes(bytes); final AtomicLong length = new AtomicLong(0); final CountDownLatch cd = new CountDownLatch(1); Utils.write(target, new ByteArrayInputStream(bytes)).subscribe(sizef -> { length.set(sizef); }, Throwable::printStackTrace, () -> { cd.countDown();/*from w w w .ja v a 2 s . c o m*/ }); if (!cd.await(2, TimeUnit.SECONDS)) { Assertions.fail("not arrived completed"); } assertThat(length.get()).isEqualTo(bytes.length); assertThat(Files.readAllBytes(target)).isEqualTo(bytes); Files.delete(target); }
From source file:io.galeb.router.services.JmxReporterService.java
private long extractDelta(final AtomicLong last, final ToLongFunction<Undertow.ListenerInfo> longFunction) { long start = System.nanoTime(); double localLast = last.get() * 1.0; double current = undertow.getListenerInfo().stream().mapToLong(longFunction).sum() * 1.0; long end = System.nanoTime(); last.set((long) current); return Math.round((current * ((double) end / (double) start)) - localLast); }
From source file:net.hydromatic.foodbench.Main.java
/** Does the work. */ private void run(String jdbcUrl, String catalog, String driverClassName) throws IOException, SQLException, ClassNotFoundException { URL url = FoodMartQuery.class.getResource("/queries.json"); InputStream inputStream = url.openStream(); ObjectMapper mapper = new ObjectMapper(); Map values = mapper.readValue(inputStream, Map.class); //noinspection unchecked List<Map<String, Object>> tests = (List) values.get("queries"); if (driverClassName != null) { Class.forName(driverClassName); }/* w w w .j a va 2s . c o m*/ Connection connection = DriverManager.getConnection(jdbcUrl); if (catalog != null) { connection.setCatalog(catalog); } Statement statement = connection.createStatement(); for (Map<String, Object> test : tests) { int id = (Integer) test.get("id"); if (!idSet.contains(id)) { continue; } String sql = (String) test.get("sql"); if (jdbcUrl.startsWith("jdbc:mysql:")) { sql = sql.replace("\"", "`"); sql = sql.replace(" NULLS FIRST", ""); sql = sql.replace(" NULLS LAST", ""); if (sql.contains("VALUES ")) { System.out.println("query id: " + id + " sql: " + sql + " skipped"); continue; } } if (jdbcUrl.startsWith("jdbc:optiq:")) { sql = sql.replace("RTRIM(", "TRIM(TRAILING ' ' FROM "); } final AtomicLong tPrepare = new AtomicLong(0); Hook.Closeable hook = Hook.JAVA_PLAN.add(new Function1<Object, Object>() { public Object apply(Object a0) { tPrepare.set(System.nanoTime()); return null; } }); try { final long t0 = System.nanoTime(); ResultSet resultSet = statement.executeQuery(sql); int n = 0; while (resultSet.next()) { ++n; } resultSet.close(); final long tEnd = System.nanoTime(); final long nanos = tEnd - t0; final long prepare = tPrepare.longValue() - t0; final long execute = tEnd - tPrepare.longValue(); System.out.println("query id: " + id + " rows: " + n + " nanos: " + NF.format(nanos) + " prepare: " + NF.format(prepare) + " execute: " + NF.format(execute) + " prepare%: " + ((float) prepare / (float) nanos * 100f)); } catch (SQLException e) { System.out.println("query id: " + id + " sql: " + sql + " error: " + e.getMessage()); if (verbose) { e.printStackTrace(); } } finally { hook.close(); } } statement.close(); connection.close(); }
From source file:com.taobao.adfs.util.Utilities.java
public static void greaterAndSet(long value, AtomicLong atomicValue) { synchronized (atomicValue) { if (value > atomicValue.get()) atomicValue.set(value); }/*from w ww.j ava 2 s . c o m*/ }