本文整理汇总了Java中java.util.concurrent.atomic.AtomicInteger.intValue方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicInteger.intValue方法的具体用法?Java AtomicInteger.intValue怎么用?Java AtomicInteger.intValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicInteger
的用法示例。
在下文中一共展示了AtomicInteger.intValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteChildren
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
/**
* Delete TGT's service tickets.
*
* @param ticket the ticket
* @return the count of tickets that were removed including child tickets and zero if the ticket was not deleted
*/
public int deleteChildren(final TicketGrantingTicket ticket) {
final AtomicInteger count = new AtomicInteger(0);
// delete service tickets
final Map<String, Service> services = ticket.getServices();
if (services != null && !services.isEmpty()) {
services.keySet().stream().forEach(ticketId -> {
if (deleteSingleTicket(ticketId)) {
LOGGER.debug("Removed ticket [{}]", ticketId);
count.incrementAndGet();
} else {
LOGGER.debug("Unable to remove ticket [{}]", ticketId);
}
});
}
return count.intValue();
}
示例2: deleteTicket
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
@Override
public int deleteTicket(final String ticketId) {
final AtomicInteger count = new AtomicInteger(0);
if (StringUtils.isBlank(ticketId)) {
return count.intValue();
}
final Ticket ticket = getTicket(ticketId);
if (ticket == null) {
return count.intValue();
}
if (ticket instanceof TicketGrantingTicket) {
if (ticket instanceof ProxyGrantingTicket) {
LOGGER.debug("Removing proxy-granting ticket [{}]", ticketId);
}
LOGGER.debug("Removing children of ticket [{}] from the registry.", ticket.getId());
final TicketGrantingTicket tgt = (TicketGrantingTicket) ticket;
count.addAndGet(deleteChildren(tgt));
final Collection<ProxyGrantingTicket> proxyGrantingTickets = tgt.getProxyGrantingTickets();
proxyGrantingTickets.stream().map(Ticket::getId).forEach(t -> count.addAndGet(this.deleteTicket(t)));
}
LOGGER.debug("Removing ticket [{}] from the registry.", ticket);
if (deleteSingleTicket(ticketId)) {
count.incrementAndGet();
}
return count.intValue();
}
示例3: execute
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
private MemgraphCypherScope execute(MemgraphCypherQueryContext ctx, CypherQuery cypherQuery) {
MemgraphCypherScope scope = MemgraphCypherScope.newSingleItemScope(MemgraphCypherScope.newEmptyItem());
ImmutableList<CypherClause> clauses = cypherQuery.getClauses();
AtomicInteger clauseIndex = new AtomicInteger(0);
for (; clauseIndex.intValue() < clauses.size(); clauseIndex.incrementAndGet()) {
scope = execute(ctx, clauses, clauseIndex, scope);
}
if (clauses.get(clauses.size() - 1) instanceof CypherReturnClause) {
return scope;
}
return MemgraphCypherScope.newEmpty();
}
示例4: getIDF
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public static double getIDF(final Map<String, List<String>> documents, String term) {
final double N = documents.size();
final AtomicInteger termCount = new AtomicInteger(0);
documents.values().stream().forEach(word -> {
termCount.addAndGet(word.contains(term) ? 1 : 0);
});
if (termCount.intValue() == 0) {
return 0;
}
double idf = Math.log(N / termCount.doubleValue());
return idf;
}
示例5: getInstanceNumber
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
private static Integer getInstanceNumber(Object impl,String interfaceId,String method,int port) {
Class clazz = impl.getClass();
AtomicInteger num = callbackCountMap.get(clazz);
if (num == null) {
num = initNum(clazz);
}
if (num.intValue() >= 2000) {
throw new RuntimeException("[JSF-24301]Callback instance have exceeding 2000 for type:" + clazz+" interfaceId "+interfaceId+" method "+method+" port"+port);
}
return num.getAndIncrement();
}
示例6: getSelectedRow
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
private static int getSelectedRow() throws Exception {
final AtomicInteger row = new AtomicInteger(-1);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
row.set(table.getSelectedRow());
}
});
return row.intValue();
}
示例7: emailTask
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
public void emailTask(final boolean batched)
{
final Date notBefore = new Date(System.currentTimeMillis() - RETRY_MILLIS);
final Date processTime = new Date();
final String attemptId = UUID.randomUUID().toString();
final ExecutorCompletionService<EmailResult<EmailKey>> completionService = new ExecutorCompletionService<EmailResult<EmailKey>>(
emailerPool);
final AtomicInteger emailCounter = new AtomicInteger();
Multimap<Long, Institution> availableInsts = institutionService.getAvailableMap();
for( Long schemaId : availableInsts.keySet() )
{
schemaDataSourceService.executeWithSchema(schemaId, new Callable<Void>()
{
@Override
public Void call()
{
while( processFirstUser(notBefore, processTime, completionService, emailCounter, attemptId,
batched) )
{
Future<EmailResult<EmailKey>> result;
while( (result = completionService.poll()) != null )
{
processResult(result, emailCounter);
}
}
return null;
}
});
}
try
{
while( emailCounter.intValue() > 0 )
{
processResult(completionService.take(), emailCounter);
}
}
catch( InterruptedException e )
{
LOGGER.error("Error waiting for emails");
}
}
示例8: testConcurrentEvaluation
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
@Test
public void testConcurrentEvaluation() throws InterruptedException, PebbleException {
PebbleEngine engine = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String templateSource = "{{ test.a }}:{{ test.b }}:{{ test.c }}:{{ test.d | upper }}";
final PebbleTemplate template = engine.getTemplate(templateSource);
ExecutorService es = Executors.newCachedThreadPool();
final AtomicInteger totalFailed = new AtomicInteger();
int numOfConcurrentEvaluations = Math.min(4, Runtime.getRuntime().availableProcessors());
final Semaphore semaphore = new Semaphore(numOfConcurrentEvaluations);
for (int i = 0; i < 10000; i++) {
semaphore.acquire();
es.submit(new Runnable() {
@Override
public void run() {
try {
int a = r.nextInt();
int b = r.nextInt();
int c = r.nextInt();
int d = r.nextInt();
TestObject testObject = new TestObject(a, b, c, "test"+d);
StringWriter writer = new StringWriter();
Map<String, Object> context = new HashMap<>();
context.put("test", testObject);
template.evaluate(writer, context);
String expectedResult = new StringBuilder().append(a).append(":").append(b).append(":")
.append(c).append(":").append("TEST").append(d).toString();
String actualResult = writer.toString();
if (!expectedResult.equals(actualResult)) {
System.out.println("Expected: " + expectedResult);
System.out.println("Actual: " + actualResult);
System.out.println("");
totalFailed.incrementAndGet();
}
} catch (IOException | PebbleException e) {
e.printStackTrace();
totalFailed.incrementAndGet();
} finally {
semaphore.release();
}
}
});
if (totalFailed.intValue() > 0) {
break;
}
}
// Wait for them all to complete
semaphore.acquire(numOfConcurrentEvaluations);
es.shutdown();
assertEquals(0, totalFailed.intValue());
}
示例9: testConcurrentEvaluationWithDifferingLocals
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
/**
* Issue #40
*
* @throws InterruptedException
* @throws PebbleException
*/
@Test
public void testConcurrentEvaluationWithDifferingLocals() throws InterruptedException, PebbleException {
final PebbleEngine engine = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();
String templateSource = "{{ 2000.234 | numberformat }}";
final PebbleTemplate template = engine.getTemplate(templateSource);
ExecutorService es = Executors.newCachedThreadPool();
final AtomicInteger totalFailed = new AtomicInteger();
int numOfConcurrentEvaluations = Math.min(4, Runtime.getRuntime().availableProcessors());
final Semaphore semaphore = new Semaphore(numOfConcurrentEvaluations);
final String germanResult = "2.000,234";
final String canadianResult = "2,000.234";
for (int i = 0; i < 1000; i++) {
semaphore.acquire();
es.submit(new Runnable() {
@Override
public void run() {
try {
final boolean isGerman = r.nextBoolean();
final Locale locale = isGerman ? Locale.GERMANY : Locale.CANADA;
final StringWriter writer = new StringWriter();
template.evaluate(writer, locale);
final String expectedResult = isGerman ? germanResult : canadianResult;
final String actualResult = writer.toString();
if (!expectedResult.equals(actualResult)) {
System.out.println(String.format("Locale: %s\nExpected: %s\nActual: %s\n",
locale.toString(), expectedResult, actualResult));
totalFailed.incrementAndGet();
}
} catch (IOException | PebbleException e) {
e.printStackTrace();
totalFailed.incrementAndGet();
} finally {
semaphore.release();
}
}
});
if (totalFailed.intValue() > 0) {
break;
}
}
// Wait for them all to complete
semaphore.acquire(numOfConcurrentEvaluations);
es.shutdown();
assertEquals(0, totalFailed.intValue());
}
示例10: testConcurrentCacheHitting
import java.util.concurrent.atomic.AtomicInteger; //导入方法依赖的package包/类
@Test
public void testConcurrentCacheHitting() throws InterruptedException, PebbleException {
final PebbleEngine engine = new PebbleEngine.Builder().strictVariables(false).build();
final ExecutorService es = Executors.newCachedThreadPool();
final AtomicInteger totalFailed = new AtomicInteger();
int numOfConcurrentThreads = Math.min(4, Runtime.getRuntime().availableProcessors());
final Semaphore semaphore = new Semaphore(numOfConcurrentThreads);
for (int i = 0; i < 100000; i++) {
semaphore.acquire();
es.submit(new Runnable() {
@Override
public void run() {
try {
PebbleTemplate template = engine.getTemplate("templates/template.concurrent1.peb");
int a = r.nextInt();
int b = r.nextInt();
int c = r.nextInt();
TestObject testObject = new TestObject(a, b, c);
StringWriter writer = new StringWriter();
Map<String, Object> context = new HashMap<>();
context.put("test", testObject);
template.evaluate(writer, context);
String expectedResult = new StringBuilder().append(a).append(":").append(b).append(":")
.append(c).toString();
String actualResult = writer.toString();
if (!expectedResult.equals(actualResult)) {
System.out.println("Expected: " + expectedResult);
System.out.println("Actual: " + actualResult);
totalFailed.incrementAndGet();
}
} catch (IOException | PebbleException e) {
e.printStackTrace();
totalFailed.incrementAndGet();
} finally {
semaphore.release();
}
}
});
// quick fail
if (totalFailed.intValue() > 0) {
break;
}
}
// Wait for them all to complete
semaphore.acquire(numOfConcurrentThreads);
es.shutdown();
assertEquals(0, totalFailed.intValue());
}