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:interoperabilite.webservice.client.ClientEvictExpiredConnections.java
public static void main(String[] args) throws Exception { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(100);//from w w w . ja v a 2 s . c o m CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).evictExpiredConnections() .evictIdleConnections(5L, TimeUnit.SECONDS).build(); try { // create an array of URIs to perform GETs on String[] urisToGet = { "http://hc.apache.org/", "http://hc.apache.org/httpcomponents-core-ga/", "http://hc.apache.org/httpcomponents-client-ga/", }; for (int i = 0; i < urisToGet.length; i++) { String requestURI = urisToGet[i]; HttpGet request = new HttpGet(requestURI); System.out.println("Executing request " + requestURI); CloseableHttpResponse response = httpclient.execute(request); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); System.out.println(EntityUtils.toString(response.getEntity())); } finally { response.close(); } } PoolStats stats1 = cm.getTotalStats(); System.out.println("Connections kept alive: " + stats1.getAvailable()); // Sleep 10 sec and let the connection evictor do its job Thread.sleep(10000); PoolStats stats2 = cm.getTotalStats(); System.out.println("Connections kept alive: " + stats2.getAvailable()); } finally { httpclient.close(); } }
From source file:org.s1p.app6.S1pKafkaApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(S1pKafkaApplication.class).web(false) .run(args);/* w ww . j av a 2 s . c o m*/ TestBean testBean = context.getBean(TestBean.class); testBean.send(new GenericMessage<>(new Foo("foo", "bar"))); context.getBean(Listener.class).latch.await(60, TimeUnit.SECONDS); context.close(); }
From source file:com.javacreed.examples.spring.Example1.java
public static void main(final String[] args) throws Exception { final ComboPooledDataSource ds = DbUtils.createDs(); try {/* w w w . j a v a 2 s . c om*/ final JdbcTemplate jdbcTemplate = new JdbcTemplate(ds); Example1.LOGGER.debug("Reading all rows"); final List<Data> rows = jdbcTemplate.query("SELECT * FROM `big_table`", Data.ROW_MAPPER); Example1.LOGGER.debug("All records read ({} records)", rows.size()); // Sleep a bit so that it shows better on the profiler TimeUnit.SECONDS.sleep(10); } finally { DbUtils.closeQuietly(ds); } Example1.LOGGER.debug("Done"); }
From source file:com.hellblazer.autoconfigure.ZookeeperLauncher.java
public static void main(String[] argv) throws Exception { if (argv.length != 2) { System.err.println("ZookeeperLauncher <config file> <timeout>"); System.exit(1);//from w w w . j av a 2 s. c o m return; } ZookeeperLauncher launcher = new ZookeeperLauncher(argv[0]); long timeout = Long.parseLong(argv[1]); launcher.start(timeout, TimeUnit.SECONDS); }
From source file:com.javacreed.examples.spring.Example2.java
public static void main(final String[] args) throws Exception { final ComboPooledDataSource ds = DbUtils.createDs(); try {// ww w . j av a2 s . com final JdbcTemplate jdbcTemplate = new JdbcTemplate(ds); Example2.LOGGER.debug("Reading all rows"); final List<Data> rows = jdbcTemplate.query(new StreamingStatementCreator("SELECT * FROM `big_table`"), Data.ROW_MAPPER); Example2.LOGGER.debug("All records read ({} records)", rows.size()); // Sleep a bit so that it shows better on the profiler TimeUnit.SECONDS.sleep(10); } finally { DbUtils.closeQuietly(ds); } Example2.LOGGER.debug("Done"); }
From source file:com.doctor.ignite.example.spring.SpringIgniteExample.java
public static void main(String[] args) throws InterruptedException { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( SpringIgniteConfig.class); Ignite ignite = applicationContext.getBean(Ignite.class); CacheConfiguration<UUID, Person> cacheConfiguration = applicationContext .getBean("CacheConfigurationForDays", CacheConfiguration.class); IgniteCache<UUID, Person> igniteCache2 = ignite.cache("cacheForDays"); if (igniteCache2 == null) { CacheConfiguration<UUID, Person> cacheConfiguration2 = new CacheConfiguration<>(cacheConfiguration); cacheConfiguration2.setName("cacheForDays"); igniteCache2 = ignite.createCache(cacheConfiguration2); System.out.println("--------createCache:" + "cacheForDays"); }/*from w ww. ja v a 2s .co m*/ Person person = new Person(UUID.randomUUID(), "doctor", BigDecimal.valueOf(88888888.888), "man", "..."); System.out.println(igniteCache2.get(person.getId())); igniteCache2.put(person.getId(), person); System.out.println(igniteCache2.get(person.getId())); TimeUnit.SECONDS.sleep(6); System.out.println(igniteCache2.get(person.getId())); System.out.println(""); Person person1 = new Person(UUID.randomUUID(), "doctor 118", BigDecimal.valueOf(88888888.888), "man", "..."); igniteCache2.put(person1.getId(), person1); Person person2 = new Person(UUID.randomUUID(), "doctor who 88 ", BigDecimal.valueOf(188888888.888), "man", "..."); igniteCache2.put(person2.getId(), person2); try (QueryCursor<List<?>> queryCursor = igniteCache2.query(new SqlFieldsQuery("select name from Person"))) { for (List<?> entry : queryCursor) { System.out.println(entry); } } applicationContext.close(); }
From source file:locking.LockingExample.java
public static void main(String[] args) throws Exception { // all of the useful sample code is in ExampleClientThatLocks.java // FakeLimitedResource simulates some external resource that can only be access by one process at a time final FakeLimitedResource resource = new FakeLimitedResource(); ExecutorService service = Executors.newFixedThreadPool(QTY); final TestingServer server = new TestingServer(); try {/*from w w w . j a v a2s .com*/ for (int i = 0; i < QTY; ++i) { final int index = i; Callable<Void> task = new Callable<Void>() { @Override public Void call() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3)); try { client.start(); ExampleClientThatLocks example = new ExampleClientThatLocks(client, PATH, resource, "Client " + index); for (int j = 0; j < REPETITIONS; ++j) { example.doWork(10, TimeUnit.SECONDS); } } catch (Throwable e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(client); } return null; } }; service.submit(task); } service.shutdown(); service.awaitTermination(10, TimeUnit.MINUTES); } finally { IOUtils.closeQuietly(server); } }
From source file:example.ReceiveNumbers.java
/** * @param args//from w w w . j ava 2 s .c om * @throws MalformedURLException * @throws JSONException */ public static void main(String[] args) throws MalformedURLException, JSONException { // TODO Auto-generated method stub JSONObject previousSub = new JSONObject( "{'id':'test-java-666','desc':'test-java-666', 'subkey':'GPS-71454020-queu'}"); MyAEONCallbacks myCallBack = new MyAEONCallbacks(); final AEONSDK sdk = new AEONSDK(Config.SUB_URL, Config.YOUR_ID, Config.YOUR_DESC); //final AEONSDK sdk = new AEONSDK(Config.SUB_URL, previousSub); JSONObject subscription = sdk.subscribe(myCallBack); if (subscription == null) { System.out.println("Something went wrong I dont have a subscription"); return; } System.out.println("subscription received " + subscription.toString()); try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* sdk.deleteSubscription(); System.out.println("Deleted subscription: if some one is publish in the channel you will lost it for ever."); try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Ok, lets have another new subscription."); subscription = sdk.subscribe(myCallBack); */ ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(new Runnable() { boolean paused = false; @Override public void run() { System.out.println("Ok lets make a little break of 5 seconds. After that the subscription" + " will continue. And messages published while our break will be delivered inmediatly"); if (!paused) { sdk.pauseSusbscription(); paused = true; } else { sdk.continueSubscription(); paused = false; } } }, 1, 5, TimeUnit.SECONDS); }
From source file:com.github.lburgazzoli.sandbox.reactor.ProcessorMain.java
public static void main(String[] args) { try {//from w w w . ja v a 2 s . c o m final Processor<Message> processor = new ProcessorSpec<Message>().dataSupplier(new MessageSupplier()) .consume(new ThrottlingMessageConsumer(10)).singleThreadedProducer().dataBufferSize(1024).get(); Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS); Thread th = new Thread(new Runnable() { public void run() { for (int i = 0; i < 20; i++) { Operation<Message> op = processor.get(); op.get().type = i; op.commit(); } } }); th.start(); th.join(); processor.shutdown(); Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.warn("Main Exception", e); } }
From source file:ch.rasc.wampspring.demo.client.Publisher.java
public static void main(String[] args) throws InterruptedException { WebSocketClient webSocketClient = new StandardWebSocketClient(); final JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); final CountDownLatch welcomeLatch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1_000_000); TextWebSocketHandler handler = new TextWebSocketHandler() { @Override//from www.j a va 2 s .c o m protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { WampMessage wampMessage = WampMessage.fromJson(jsonFactory, message.getPayload()); if (wampMessage instanceof WelcomeMessage) { latch.countDown(); } } }; Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wamp"); future.addCallback(wss -> { // Waiting for WELCOME message try { welcomeLatch.await(5, TimeUnit.SECONDS); start[0] = System.currentTimeMillis(); for (int i = 0; i < 1_000_000; i++) { PublishMessage publishMessage = new PublishMessage("/test/myqueue", i); try { wss.sendMessage(new TextMessage(publishMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING PUBLISH_MESSAGE" + e); } latch.countDown(); } } catch (Exception e1) { System.out.println("SENDING PUBLISH MESSAGES: " + e1); } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); }