List of usage examples for java.util.concurrent TimeUnit SECONDS
TimeUnit SECONDS
To view the source code for java.util.concurrent TimeUnit SECONDS.
Click Source Link
From source file:org.zhangmz.pickles.helper.AuthorityHelper.java
@PostConstruct public void init() { logger.debug("? " + loginTimeoutSecs); // expireAfterWrite ?expireAfterAccess ? // CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(loginTimeoutSecs, TimeUnit.SECONDS).build(); loginUsers = CacheBuilder.newBuilder().maximumSize(1000) .expireAfterAccess(loginTimeoutSecs, TimeUnit.SECONDS).build(); loginEndusers = CacheBuilder.newBuilder().maximumSize(1000) .expireAfterAccess(loginTimeoutSecs, TimeUnit.SECONDS).build(); }
From source file:com.netflix.spinnaker.halyard.deploy.provider.v1.KubernetesProvider.java
@Override public void bootstrapClouddriver() { JobRequest request = new JobRequest().setTokenizedCommand(Arrays.asList("kubectl", "create", "-f", "-")) .setTimeoutMillis(TimeUnit.MINUTES.toMillis(TIMEOUT_MINUTES)); InputStream cloudddriverConfig = getClass().getResourceAsStream(CLOUDRIVER_CONFIG_PATH); String jobId = jobExecutor.startJob(request, System.getenv(), cloudddriverConfig); JobStatus jobStatus = jobExecutor.backoffWait(jobId, TimeUnit.SECONDS.toMillis(MIN_POLL_INTERVAL_SECONDS), TimeUnit.SECONDS.toMillis(MAX_POLL_INTERVAL_SECONDS)); System.out.println(jobStatus.getStdOut()); System.out.println(jobStatus.getStdErr()); }
From source file:com.acmutv.ontoqa.tool.runtime.RuntimeManager.java
/** * Registers a periodic task./* ww w . j av a 2s. co m*/ * @param task the task to execute. * @param delay the delay to first execution. * @param period the period between executions. * @param timeout the time to interruption. * @param unit the time unit. */ private static void registerPeriodic(Runnable task, long delay, long period, long timeout, TimeUnit unit) { final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); final ScheduledFuture<?> handler = scheduler.scheduleAtFixedRate(task, delay, period, unit); if (timeout > 0) { Runnable interrupt = () -> handler.cancel(true); scheduler.schedule(interrupt, timeout, TimeUnit.SECONDS); } }
From source file:com.parallax.server.blocklyprop.monitoring.Monitor.java
private void init() { if (consoleEnabled) { ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) .convertDurationsTo(TimeUnit.MILLISECONDS).build(); reporter.start(consoleReportingInterval, TimeUnit.SECONDS); }//w ww . j a v a 2s . c om if (graphiteEnabled) { final PickledGraphite pickledGraphite = new PickledGraphite( new InetSocketAddress(graphiteServerAddress, graphiteServerPort)); final GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metrics) .prefixedWith(graphitePrefix).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL) .build(pickledGraphite); graphiteReporter.start(graphiteReportingInterval, TimeUnit.SECONDS); } InstrumentedAppender appender = new InstrumentedAppender(metrics); appender.activateOptions(); LogManager.getRootLogger().addAppender(appender); MemoryUsageGaugeSet memoryUsageGaugeSet = new MemoryUsageGaugeSet(); metrics.registerAll(memoryUsageGaugeSet); GarbageCollectorMetricSet garbageCollectorMetricSet = new GarbageCollectorMetricSet(); metrics.registerAll(garbageCollectorMetricSet); }
From source file:com.loyalty.controllers.DashboardController.java
@Override public void initialize(URL url, ResourceBundle rb) { try {//w w w . ja v a2 s . c om kioskDTO = getService().activate(); getScheduledExecutorService().scheduleAtFixedRate(this::renewPromotions, 0, 10, TimeUnit.SECONDS); animate(); } catch (KioskException ke) { getDialogManager().showInformation(ke.getMessage()); } catch (IOException ioe) { getDialogManager().showInformation( "Client Application could not login to server. Check Your credentials and Kiosk License."); Platform.exit(); } // //ipAddress = new IPAddress().getIPAddress(); // HashMap<String, String> params = new HashMap<String, String>(); // params.put("ip", ipAddress); // params.put("status", ""); // response = new AppHelper().performPostCall(KIOSK_REGISTER_URL, params); // try { // JSONObject jsonObject = new JSONObject(response); // String msg = jsonObject.getString("msg"); // System.out.println(msg); // } catch (JSONException ex) { // ex.printStackTrace(); // } // // response_promotion = new AppHelper().performPostCall(GET_PROMOTION_OFFER_URL, params); // System.err.println(response_promotion); // if (response_promotion != null) { // try { // JSONArray jaaraa = new JSONArray(response_promotion); // // for (int i = 0; i < jaaraa.length(); i++) { // JSONObject object = jaaraa.getJSONObject(0); // String offername = object.getString("offername"); // String promotionname = object.getString("promotionname"); // String description = object.getString("description"); // String expire = object.getString("expire"); // //JSONObject JOBJ = new JSONObject(response_promotion[0]); // // System.out.println("parwez" + aa); // // } // lbl_promotion.setText(promotionname + " and " + offername + " be hurry offer valid till " + expire); // lbl_promotion.setStyle("-fx-background-color: #DF013A;-fx-background-radius: 10 10 10 10;-fx-height:90px;"); // TranslateTransition transition = TranslateTransitionBuilder.create() // .duration(new Duration(7500)) // .node(lbl_promotion) // .interpolator(Interpolator.LINEAR) // .cycleCount(Timeline.INDEFINITE) // .build(); // // GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // int width = 1; // //gd.getDisplayMode().getWidth(); // // transition.setFromX(width); // transition.setToX(-width); // transition.play(); // // } catch (JSONException ex) { // Logger.getLogger(DashboardController.class.getName()).log(Level.SEVERE, null, ex); // } // } else { // } System.out.println("initialized"); }
From source file:com.buaa.cfs.nfs3.AsyncDataService.java
public AsyncDataService() { threadFactory = new ThreadFactory() { @Override/*w ww. j a v a 2s. c o m*/ public Thread newThread(Runnable r) { return new Thread(threadGroup, r); } }; executor = new ThreadPoolExecutor(CORE_THREADS_PER_VOLUME, MAXIMUM_THREADS_PER_VOLUME, THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); // This can reduce the number of running threads executor.allowCoreThreadTimeOut(true); }
From source file:com.sm.store.server.StoreServerHandler.java
private void init() { if (Runtime.getRuntime().availableProcessors() > maxThreads) this.maxThreads = Runtime.getRuntime().availableProcessors(); if (maxQueue < maxThreads * 1000) maxQueue = maxThreads * 1000;/* www.j av a 2 s . co m*/ BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue); threadPools = new ThreadPoolExecutor(maxThreads, maxThreads, 30, TimeUnit.SECONDS, queue, new ThreadPoolFactory("store")); }
From source file:com.artisan.hivemq.callbacks.AuthenticationCallback.java
@Override @Cached(timeToLive = 300, timeUnit = TimeUnit.SECONDS) public Boolean checkCredentials(final ClientCredentialsData clientCredentialsData) throws AuthenticationException { /*TODO: In a production ready plugin you should cache here if possible!! You can use hte @Cache Annotation for that or implement caching yourself */ final HttpPost httpPost = new HttpPost(MOCK_HTTP_SERVICE); CloseableHttpResponse response = null; try {//from w w w.j av a 2s . co m response = httpClient.execute(httpPost); final HttpEntity entity = response.getEntity(); if (entity != null) { final HashMap result = objectMapper.readValue(EntityUtils.toString(entity), HashMap.class); if ("valid".equals(result.get("auth"))) { return true; } } } catch (JsonParseException e) { log.error("Error while parsing the results from the webservice call", e); } catch (JsonMappingException e) { log.error("Error while parsing the results from the webservice call", e); } catch (ClientProtocolException e) { log.error("There was an error in the HTTP communication with the server", e); } catch (IOException e) { log.error("Could not get valid results from the webservice", e); } finally { closeGracefully(response); } //If we're getting here, we didn't get a valid response from the webservice return false; }
From source file:com.comcast.cats.vision.concurrent.RemoteWorkerTest.java
public void example() throws InterruptedException { CatsEventDispatcher dispatcher = new CatsEventDispatcherImpl(); Settop settop = new MockSettop() { private static final long serialVersionUID = 1L; public boolean pressKey(RemoteCommand command) { LOGGER.info("pressKey"); return true; }//from w ww . ja va 2 s. c o m }; dispatcher.addListener(this, CatsEventType.REMOTE_RESPONSE); RemoteEvent evt = new RemoteEvent(ActionType.PRESS, RemoteCommand.GUIDE, "10", null); ExecutorService executor = Executors.newFixedThreadPool(5); executor.execute(new PressKeyWorker(settop, evt, dispatcher)); executor.awaitTermination(5, TimeUnit.SECONDS); }
From source file:com.unknown.pkg.ConfiguredTokenApplicationIT.java
@Test public void retrieveToken() throws InterruptedException { // give the controller a chance to initialize TimeUnit.SECONDS.sleep(2); Assertions.assertThat(tokens.isRunning()).isTrue(); // calling start after it is started should not cause any errors tokens.start();//from w w w. ja v a 2 s . c o m // it should be running Assertions.assertThat(tokens.isRunning()).isTrue(); testing(); accessTokens.invalidate("firstService"); tokens.stop(new Runnable() { @Override public void run() { System.out.println("STOPPED"); } }); // tokens.stop(); Assertions.assertThat(tokens.isRunning()).isFalse(); tokens.start(); Assertions.assertThat(tokens.isRunning()).isTrue(); TimeUnit.SECONDS.sleep(2); testing(); System.out.println("KILL"); }