List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:com.lang.pat.kafkairc.Consumer.java
public void shutdown() { if (consumer != null) { consumer.shutdown();// w ww.j a v a 2s . c o m } if (executor != null) { executor.shutdown(); } try { if (!executor.awaitTermination(5000, TimeUnit.MILLISECONDS)) { System.out.println("! Error clean close, exiting uncleanly."); } } catch (InterruptedException e) { System.out.println("! Process interrupted during shutdown, exiting uncleanly."); } }
From source file:com.github.seleniumpm.SeleniumWebdriver.java
protected void setTimeouts() { driver.manage().timeouts().implicitlyWait(elementTimeout, TimeUnit.MILLISECONDS); if (!(driver instanceof HtmlUnitDriver)) driver.manage().timeouts().pageLoadTimeout(pageTimeout, TimeUnit.MILLISECONDS); }
From source file:metlos.executors.batch.BatchExecutorTest.java
public void testTimingOfFewTasks_SingleThreaded() throws Exception { int nofThreads = 1; int nofJobs = 10; int taskDurationMillis = 100; long minimalDuration = rapidFireSimpleExecutorTime(taskDurationMillis, nofJobs, nofThreads); BatchExecutor ex = getExecutor(nofThreads); List<Callable<Void>> tasks = getCallables(taskDurationMillis, nofJobs); long expectedDuration = minimalDuration * 2; long actualDuration = measureExecutionTime(System.currentTimeMillis(), ex.invokeAllWithin(tasks, expectedDuration, TimeUnit.MILLISECONDS)); long min = (long) (expectedDuration * 0.85); long max = (long) (expectedDuration * 1.15); LOG.info("testTimingOfFewTasks_SingleThreaded() stats: expectedDuration=" + expectedDuration + ", actualDuration=" + actualDuration + ", diff=" + (actualDuration - expectedDuration)); assert actualDuration > min && actualDuration < max : "Duration should have been something between " + min + " and " + max + "ms (ideally " + expectedDuration + ") but was " + actualDuration + "ms."; }
From source file:com.mapr.synth.CommonPointOfCompromiseTest.java
@Test public void testCompromise() throws IOException, ParseException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long start = df.parse("2014-01-01 00:00:00").getTime(); SchemaSampler s = new SchemaSampler( Resources.asCharSource(Resources.getResource("schema013.json"), Charsets.UTF_8).read()); long exploitStart = df.parse("2014-01-20 00:00:00").getTime(); long exploitEnd = df.parse("2014-02-20 00:00:00").getTime(); int exploitStartDay = (int) TimeUnit.DAYS.convert(exploitStart - start, TimeUnit.MILLISECONDS); int[] transactionsByDay = new int[DAYS_COUNTED]; int[] compromiseByDay = new int[DAYS_COUNTED]; int[] fraudByDay = new int[DAYS_COUNTED]; Multiset<Integer> fraudUserCounts = HashMultiset.create(); Multiset<Integer> nonfraudUserCounts = HashMultiset.create(); Multiset<Integer> allMerchantCounts = HashMultiset.create(); int fraudAccounts = 0; Set<Integer> merchantHistory = Sets.newHashSet(); // these collect the evolution of the contingency table for just merchant 0 and are indexed by time relative to exploit window. int exploitLength = (int) (TimeUnit.DAYS.convert(exploitEnd - exploitStart, TimeUnit.MILLISECONDS)) + 1; // exploitLength = 5; int[] atmTotal = new int[exploitLength]; int[] atmFraud = new int[exploitLength]; int[] atmNonFraud = new int[exploitLength]; int[] nonAtmFraud = new int[exploitLength]; int[] nonAtmNonFraud = new int[exploitLength]; for (int userId = 0; userId < USER_COUNT; userId++) { JsonNode sample = s.sample();// w w w . j a v a 2s . c o m merchantHistory.clear(); boolean userHasFraud = false; int[] hasFraudPerUser = new int[exploitLength]; for (JsonNode record : sample.get("history")) { long timestamp = record.get("timestamp").asLong() * 1000; int day = (int) ((timestamp - start) / TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS)); if (day >= DAYS_COUNTED || day >= exploitStartDay + exploitLength) { break; } if (record.get("compromise").asInt() > 0) { compromiseByDay[day]++; } boolean isFraud = record.get("fraud").asInt() > 0; if (isFraud) { fraudByDay[day]++; } transactionsByDay[day]++; // only record history up to the beginning of the exploit window int merchant = record.get("merchant").asInt(); if (timestamp < exploitStart) { merchantHistory.add(merchant); } // only consider fraud indicators during the exploit window if (timestamp >= exploitStart && timestamp <= exploitEnd) { // any fraud in the window marks the user if (isFraud) { // first time we see fraud indication in exploit window, we set flags for the rest of the window if (!userHasFraud) { int eday = day - exploitStartDay; for (int i = eday; i < exploitLength; i++) { hasFraudPerUser[i] = 1; } } userHasFraud = true; } } } // we collect flags for each day and then only count this user once. Necessary because multiple // transactions can occur on each day and we don't want to count all of them. int atmInHistory = merchantHistory.contains(0) ? 1 : 0; for (int day = 0; day < exploitLength; day++) { atmTotal[day] += atmInHistory; atmFraud[day] += atmInHistory * hasFraudPerUser[day]; atmNonFraud[day] += atmInHistory * (1 - hasFraudPerUser[day]); nonAtmFraud[day] += (1 - atmInHistory) * hasFraudPerUser[day]; nonAtmNonFraud[day] += (1 - atmInHistory) * (1 - hasFraudPerUser[day]); } if (userHasFraud) { fraudAccounts++; for (Integer merchant : merchantHistory) { fraudUserCounts.add(merchant); allMerchantCounts.add(merchant); } } else { for (Integer merchant : merchantHistory) { nonfraudUserCounts.add(merchant); allMerchantCounts.add(merchant); } } } int k1 = fraudAccounts; int k2 = USER_COUNT - k1; try (PrintStream out = new PrintStream(new FileOutputStream("scores.tsv"))) { out.printf("merchant\tk11\tk12\tk21\tk22\tk.1\tscore\n"); for (Integer merchant : allMerchantCounts.elementSet()) { int k11 = fraudUserCounts.count(merchant); int k12 = k1 - k11; int k21 = nonfraudUserCounts.count(merchant); int k22 = k2 - k21; out.printf("%d\t%d\t%d\t%d\t%d\t%d\t%.1f\n", merchant, k11, k12, k21, k22, allMerchantCounts.count(merchant), LogLikelihood.rootLogLikelihoodRatio(k11, k12, k21, k22)); } } try (PrintStream out = new PrintStream(new FileOutputStream("counts.tsv"))) { out.printf("day\tcompromises\tfrauds\ttransactions\n"); for (int i = 0; i < compromiseByDay.length; i++) { out.printf("%d\t%d\t%d\t%d\n", i, compromiseByDay[i], fraudByDay[i], transactionsByDay[i]); } } try (PrintStream out = new PrintStream(new FileOutputStream("growth.tsv"))) { out.printf("day\tatm.total\tk11\tk12\tk21\tk22\tscore\n"); for (int i = 0; i < exploitLength; i++) { int k11 = atmFraud[i]; int k12 = nonAtmFraud[i]; int k21 = atmNonFraud[i]; int k22 = nonAtmNonFraud[i]; out.printf("%d\t%d\t%d\t%d\t%d\t%d\t%.1f\n", i, atmTotal[i], k11, k12, k21, k22, LogLikelihood.rootLogLikelihoodRatio(k11, k12, k21, k22)); } } }
From source file:com.cisco.oss.foundation.message.AbstractMessageDispatcher.java
public AbstractMessageDispatcher(ConcurrentMessageHandler concurrentMessageHandler) { this.concurrentMessageHandler = concurrentMessageHandler; Configuration configuration = ConfigurationFactory.getConfiguration(); int maxThreadPoolSize = configuration.getInt(MessageConstants.QUEUE_SIZE_PROPERTY); int waitingQueueSize = configuration.getInt(MessageConstants.WAITING_QUEUE_SIZE_PROPERTY); waitingList = new CopyOnWriteArrayList<Message>(); try {//from w w w .j av a 2 s. c o m if (waitingQueueSize > 0) { blockingWaitingQueue = new CapacityEnsurableLinkedBlockingQueue<Runnable>(waitingQueueSize); } else { blockingWaitingQueue = new CapacityEnsurableLinkedBlockingQueue<Runnable>(); } } catch (Exception ex) { LOGGER.error("Failed to create message dispatcher", ex); } executorService = new ThreadPoolExecutor(maxThreadPoolSize, maxThreadPoolSize, 0L, TimeUnit.MILLISECONDS, blockingWaitingQueue); //Executors.newFixedThreadPool(maxThreadPoolSize); }
From source file:com.bodybuilding.argos.discovery.ClusterListDiscovery.java
public ClusterListDiscovery(RestTemplate restTemplate) { super(UPDATE_INTERVAL, TimeUnit.MILLISECONDS); this.restTemplate = restTemplate; }
From source file:com.linkedin.pinot.perf.BenchmarkFileRead.java
@Benchmark @BenchmarkMode({ Mode.SampleTime })//from w ww.j ava2s.co m @OutputTimeUnit(TimeUnit.MILLISECONDS) public void readSVs() throws IOException { int rows = 25000000; int columnSizeInBits = 3; boolean isMMap = true; boolean hasNulls = false; FixedBitCompressedSVForwardIndexReader reader = new FixedBitCompressedSVForwardIndexReader(file, rows, columnSizeInBits, isMMap, hasNulls); int[] result2 = new int[rows]; for (int i = 0; i < rows; i++) { result2[i] = reader.getInt(i); } }
From source file:com.couchbase.trombi.services.GeoService.java
@Cacheable("cities") public CityInfo findCity(String cityName, String countryName) { GeoApiContext context = new GeoApiContext().setApiKey(geoApiKey); GeocodingResult[] results = GeocodingApi.newRequest(context) .components(ComponentFilter.locality(cityName), ComponentFilter.country(countryName)) .awaitIgnoreError();/* ww w . j a va2 s . c om*/ LatLng location = results[0].geometry.location; String stdCity = cityName; String stdCountry = countryName; for (AddressComponent ac : results[0].addressComponents) { for (AddressComponentType acType : ac.types) { if (acType == AddressComponentType.COUNTRY) { stdCountry = ac.longName; } else if (acType == AddressComponentType.LOCALITY) { stdCity = ac.longName; } } } TimeZone tz = TimeZoneApi.getTimeZone(context, location).awaitIgnoreError(); return new CityInfo(stdCity, stdCountry, new Point(location.lat, location.lng), (int) TimeUnit.MILLISECONDS.toHours(tz.getRawOffset())); }
From source file:com.buaa.cfs.utils.ShutdownThreadsHelper.java
/** * @param service {@link ExecutorService to be shutdown} * @param timeoutInMs time to wait for {@link * ExecutorService#awaitTermination(long, TimeUnit)} * calls in milli seconds. * @return <tt>true</tt> if the service is terminated, * <tt>false</tt> otherwise/*ww w.j a v a 2 s .c o m*/ * @throws InterruptedException */ public static boolean shutdownExecutorService(ExecutorService service, long timeoutInMs) throws InterruptedException { if (service == null) { return true; } service.shutdown(); if (!service.awaitTermination(timeoutInMs, TimeUnit.MILLISECONDS)) { service.shutdownNow(); return service.awaitTermination(timeoutInMs, TimeUnit.MILLISECONDS); } else { return true; } }
From source file:com.microsoft.office.integration.test.ContactsAsyncTestCase.java
public void testRead() { // create contact first prepareContact();/*w w w .j a v a 2 s. c om*/ counter = new CountDownLatch(1); Futures.addCallback(Me.flushAsync(), new FutureCallback<Void>() { public void onFailure(Throwable t) { reportError(t); counter.countDown(); } public void onSuccess(Void result) { try { readAndCheck(); // clean-up removeContact(); } catch (Throwable t) { reportError(t); } counter.countDown(); } }); try { if (!counter.await(60000, TimeUnit.MILLISECONDS)) { fail("testRead() timed out"); } } catch (InterruptedException e) { fail("testRead() has been interrupted"); } }