Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicInteger


        this.initialModel = initialModel;
        this.initialRole = initialModel.currentRole();
        this.models = new ConcurrentHashMap<SpecificModel, Object>();
        this.result = new PriorityBlockingQueue<Challenge<SpecificRole, SpecificFinding, SpecificModel>>();
        this.bestMove = new ConcurrentHashMap<SpecificRole, Integer>();
        this.instances = new AtomicInteger(0);
        this.timeoutForSnapshot = timeoutForSnapshot;
        this.startTime = System.currentTimeMillis();
        this.fullfilled = false;
        this.termination = new Semaphore(0);
        this.feedAssetCache = feedAssetCache;
View Full Code Here


        }
    }
   
    public void inc(final E obj) {
        if (obj == null) return;
        AtomicInteger score = this.map.get(obj);
        if (score != null) {
            score.incrementAndGet();
            return;
        }
        synchronized (map) {
            score = this.map.get(obj);
            if (score == null) {
                this.map.put(obj, new AtomicInteger(1));
                return;
            }
        }
        score.incrementAndGet();
    }
View Full Code Here

        score.incrementAndGet();
    }
   
    public void dec(final E obj) {
        if (obj == null) return;
        AtomicInteger score;
        synchronized (map) {
            score = this.map.get(obj);
            if (score == null) {
                this.map.put(obj, new AtomicInteger(-1));
                return;
            }
        }
        score.decrementAndGet();
    }
View Full Code Here

        score.decrementAndGet();
    }
   
    public void set(final E obj, final int newScore) {
        if (obj == null) return;
        AtomicInteger score;
        synchronized (map) {
            score = this.map.get(obj);
            if (score == null) {
                this.map.put(obj, new AtomicInteger(newScore));
                return;
            }
        }      
        score.getAndSet(newScore);
    }
View Full Code Here

        });

        Table table = dataContext.getDefaultSchema().getTables()[0];

        dataContexts.put(filename, dataContext);
        counters.put(filename, new AtomicInteger(1));
        outputWriter = new CsvOutputWriter(dataContext, filename, table, columns);

        // write the headers
      } else {
        Table table = dataContext.getDefaultSchema().getTables()[0];
View Full Code Here

    synchronized (counters) {
      final DatastoreOutputWriter outputWriter = new DatastoreOutputWriter(datastoreName, tableName, directory,
          columns, creationDelegate, truncate);

      AtomicInteger counter = counters.get(outputWriter.getJdbcUrl());
      if (counter == null) {
        counter = new AtomicInteger();
        counters.put(outputWriter.getJdbcUrl(), counter);
      }
      counter.incrementAndGet();

      return outputWriter;
    }
  }
View Full Code Here

        dataContext = new ExcelDataContext(file);

        Table table = getTable(dataContext, sheetName, columns);

        dataContexts.put(filename, dataContext);
        counters.put(filename, new AtomicInteger(1));
        outputWriter = new ExcelOutputWriter(dataContext, filename, table, columns);

        // write the headers
      } else {
        Table table = getTable(dataContext, sheetName, columns);
View Full Code Here

    }

    protected void configExecutors() {
        executorService = Executors.newSingleThreadExecutor(new ThreadFactory() {

            private final AtomicInteger count = new AtomicInteger();

            @Override
            public Thread newThread(final Runnable runnable) {
                Thread t = new Thread(runnable, "Atmosphere-BroadcasterConfig-" + count.getAndIncrement());
                t.setDaemon(true);
                return t;
            }
        });
        defaultExecutorService = executorService;

        asyncWriteService = Executors.newCachedThreadPool(new ThreadFactory() {

            private final AtomicInteger count = new AtomicInteger();

            @Override
            public Thread newThread(final Runnable runnable) {
                Thread t = new Thread(runnable, "Atmosphere-AsyncWrite-" + count.getAndIncrement());
                t.setDaemon(true);
                return t;
            }
        });
        defaultAsyncWriteService = asyncWriteService;
View Full Code Here

      }
    }
  }

  public void testMultiThreadedWriting() throws Exception {
    final AtomicInteger datastoreCount = new AtomicInteger();
    final OutputWriterScenarioHelper scenarioHelper = new OutputWriterScenarioHelper();

    final DatastoreCreationDelegate creationDelegate = new DatastoreCreationDelegate() {

      @Override
      public synchronized void createDatastore(Datastore datastore) {
        if (_datastore != null) {
          assertEquals(_datastore, datastore);
        }
        _datastore = datastore;
        datastoreCount.incrementAndGet();
      }
    };

    final InputColumn<?>[] columns = scenarioHelper.getColumns().toArray(new InputColumn[0]);

    // creating 9 similar writers that all write at the same time
    Thread[] threads = new Thread[9];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = new Thread() {
        public void run() {
          try {
            OutputWriter writer = DatastoreOutputWriterFactory.getWriter(outputDir, creationDelegate, "ds",
                "tab", false, columns);
            scenarioHelper.writeExampleData(writer);
          } catch (Exception e) {
            _exception = e;
          }
        };
      };
    }
    for (int i = 0; i < threads.length; i++) {
      threads[i].start();
    }
    for (int i = 0; i < threads.length; i++) {
      threads[i].join();
    }

    if (_exception != null) {
      throw _exception;
    }
    assertEquals(9, datastoreCount.get());

    assertNotNull(_datastore);
    DataContextProvider dataContextProvider = _datastore.getDataContextProvider();
    DataContext dc = dataContextProvider.getDataContext();
    dc.refreshSchemas();
View Full Code Here

  public final boolean query(final String sQuery, final boolean bIgnoreErrors) {
    lQueryCount++;

    final String sConnection = getKey();

    AtomicInteger ai = chmQueryCount.get(sConnection);
    AtomicLong al = null;
    if (ai == null) {
      ai = new AtomicInteger(1);
      chmQueryCount.put(sConnection, ai);

      al = new AtomicLong(0);
      chmQueryTime.put(sConnection, al);
    } else {
      ai.incrementAndGet();

      al = chmQueryTime.get(sConnection);
    }

    if (al == null) {
View Full Code Here

TOP

Related Classes of java.util.concurrent.atomic.AtomicInteger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.