List of usage examples for java.util.concurrent.atomic AtomicInteger AtomicInteger
public AtomicInteger(int initialValue)
From source file:Main.java
public static ThreadFactory newGenericThreadFactory(final String processName, final boolean isDaemon) { return new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override//from w w w . j a v a 2 s .com public Thread newThread(Runnable r) { Thread thread = new Thread(r, String.format("%s_%d", processName, this.threadIndex.incrementAndGet())); thread.setDaemon(isDaemon); return thread; } }; }
From source file:AtomicFloat.java
public AtomicFloat(float value) { this.value = new AtomicInteger(i(value)); }
From source file:com.amazonaws.http.DelegatingDnsResolverTest.java
@Before public void resetClientConfiguration() { dnsResolutionCounter = new AtomicInteger(0); requestedHosts = new CopyOnWriteArraySet<String>(); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.withMaxErrorRetry(0); clientConfiguration.withDnsResolver(new DnsResolver() { DnsResolver system = new SystemDefaultDnsResolver(); @Override//from w w w . j a v a 2 s .c o m public InetAddress[] resolve(String host) throws UnknownHostException { dnsResolutionCounter.incrementAndGet(); requestedHosts.add(host); return system.resolve(host); } }); testedClient = new AmazonHttpClient(clientConfiguration); }
From source file:CreateTest.java
static void doTestLoop() { nCalls = new AtomicInteger(0); done = false;/*ww w. j a v a2s . c o m*/ for (int i = 0; i < target; i++) work(); synchronized (lock) { while (!done) try { lock.wait(); } catch (Exception e) { } } }
From source file:com.xiaomi.linden.file.TestFileChangeWatcher.java
@Test public void testFileChangeWatcher() throws IOException, InterruptedException { final AtomicInteger events = new AtomicInteger(0); final Function<String, Object> callback = new Function<String, Object>() { @Override// ww w . java2s.c o m public String apply(String absolutePath) { events.incrementAndGet(); return null; } }; File dir = new File("tmp"); if (!dir.exists()) { dir.mkdir(); } File file = new File("tmp/test.txt"); file.createNewFile(); fileChangeWatcher = new FileChangeWatcher(file.getAbsolutePath(), callback, 10); fileChangeWatcher.start(); directoryChangeWatcher = new DirectoryChangeWatcher(dir.getAbsolutePath(), callback, 10); directoryChangeWatcher.start(); Files.write("Hello", file, Charsets.UTF_8); Thread.sleep(10 * 1000); Assert.assertEquals(2, events.get()); FileUtils.deleteQuietly(file); FileUtils.deleteDirectory(dir); }
From source file:com.alibaba.rocketmq.storm.domain.MessageStat.java
public MessageStat(int failureTimes) { this.failureTimes = new AtomicInteger(failureTimes); }
From source file:dk.statsbiblioteket.util.JobControllerTest.java
public void testPopFinished() throws Exception { final int JOBS = 10; final AtomicInteger counter = new AtomicInteger(0); JobController<Long> controller = new JobController<Long>(10) { @Override//w ww . j a v a 2 s . c o m protected void afterExecute(Future<Long> finished) { counter.incrementAndGet(); } }; for (int i = 0; i < JOBS; i++) { synchronized (Thread.currentThread()) { Thread.currentThread().wait(10); } controller.submit(new Shout(50)); } int first = controller.popFinished().size(); synchronized (Thread.currentThread()) { Thread.currentThread().wait(60); } int second = controller.popFinished().size(); assertTrue("The first pop should yield some results. Got " + first, first > 0); assertTrue("The second pop should yield some results. Got " + second, second > 0); log.info("first popFinished: " + first + ", second popFinished: " + second); assertEquals("The total pops should be correct", 10, first + second); assertEquals("The callback count should be correct", 10, counter.get()); }
From source file:com.ksc.http.DelegatingDnsResolverTest.java
@Before public void resetClientConfiguration() { dnsResolutionCounter = new AtomicInteger(0); requestedHosts = new CopyOnWriteArraySet<String>(); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.withMaxErrorRetry(0); clientConfiguration.withDnsResolver(new DnsResolver() { DnsResolver system = new SystemDefaultDnsResolver(); @Override//from w w w . ja v a2 s .c om public InetAddress[] resolve(String host) throws UnknownHostException { dnsResolutionCounter.incrementAndGet(); requestedHosts.add(host); return system.resolve(host); } }); testedClient = new KSCHttpClient(clientConfiguration); }
From source file:alfio.util.PreReservedTicketDistributor.java
public PreReservedTicketDistributor(int requestedTickets) { this.requestedTickets = new AtomicInteger(requestedTickets); }
From source file:org.eclipse.swt.snippets.Snippet366.java
private static void makeAlignGroup() { Group alignGroup = new Group(shell, SWT.None); alignGroup.setLayout(new RowLayout()); alignGroup.setText("Alignment group"); final AtomicInteger prevDir = new AtomicInteger(0); final Button alignmentButton = new Button(alignGroup, SWT.ARROW | SWT.UP); alignmentButton.addListener(SWT.MouseDown, event -> { switch (prevDir.get()) { case 0:/*from ww w . jav a 2s.co m*/ alignmentButton.setAlignment(SWT.RIGHT); prevDir.set(1); break; case 1: alignmentButton.setAlignment(SWT.DOWN); prevDir.set(2); break; case 2: alignmentButton.setAlignment(SWT.LEFT); prevDir.set(3); break; case 3: alignmentButton.setAlignment(SWT.UP); prevDir.set(0); default: break; } }); }