當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicInteger.intValue方法代碼示例

本文整理匯總了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();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:AbstractTicketRegistry.java

示例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();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:34,代碼來源:AbstractTicketRegistry.java

示例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();
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:13,代碼來源:QueryExecutor.java

示例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;
}
 
開發者ID:ag-sc,項目名稱:JLink,代碼行數:14,代碼來源:TFIDF.java

示例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();
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:14,代碼來源:CallbackUtil.java

示例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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:bug7068740.java

示例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");
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:43,代碼來源:NotificationServiceImpl.java

示例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());
}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:62,代碼來源:ConcurrencyTest.java

示例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());
}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:66,代碼來源:ConcurrencyTest.java

示例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());
}
 
開發者ID:flapdoodle-oss,項目名稱:de.flapdoodle.solid,代碼行數:59,代碼來源:CacheTest.java


注:本文中的java.util.concurrent.atomic.AtomicInteger.intValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。