List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:org.sourcepit.docker.watcher.Main.java
public static void main(String[] args) throws IOException { final HttpClientFactory clientFactory = new HttpClientFactory() { @Override/*from w w w. ja va 2 s . c o m*/ public CloseableHttpClient createHttpClient() { return HttpClients.createDefault(); } }; final String dockerDaemonUri = "http://192.168.56.101:2375"; final String consulAgentUri = "http://192.168.56.101:8500"; final BlockingQueue<List<JsonObject>> queue = new LinkedBlockingQueue<>(); final ConsulForwarder consulForwarder = new ConsulForwarder(clientFactory.createHttpClient(), consulAgentUri); final Thread containerStateDispatcher = new Thread("Consul Forwarder") { @Override public void run() { while (true) { try { consulForwarder.forward(queue.take()); } catch (InterruptedException e) { break; } catch (Exception e) { LOG.error("Error while forwarding Docker container state to Consul.", e); } } } }; containerStateDispatcher.start(); final DockerWatcher watcher = new DockerWatcher(clientFactory, dockerDaemonUri) { @Override protected void handle(List<JsonObject> containerState) { queue.add(containerState); } }; Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { watcher.stop(); while (containerStateDispatcher.isAlive()) { containerStateDispatcher.interrupt(); try { Thread.sleep(100L); } catch (InterruptedException e) { } } } }); watcher.start(); }
From source file:edu.kit.dama.transfer.client.impl.GUIDownloadClient.java
/** * The main entry point/*from ww w . ja v a 2 s. c o m*/ * * @param args The command line argument array */ public static void main(String[] args) { int result = 0; GUIDownloadClient client; try { client = new GUIDownloadClient(args); Thread.currentThread().setUncaughtExceptionHandler(client); client.setVisible(); while (client.isVisible()) { try { Thread.sleep(DateUtils.MILLIS_PER_SECOND); } catch (InterruptedException ie) { } } } catch (TransferClientInstatiationException ie) { LOGGER.error("Failed to instantiate GUI client", ie); result = 1; } catch (CommandLineHelpOnlyException choe) { result = 0; } System.exit(result); }
From source file:com.coherentlogic.treasurydirect.client.applications.MainApplication.java
public static void main(String[] unused) throws InterruptedException { try {/*from w w w .java2s. c o m*/ SpringApplicationBuilder builder = new SpringApplicationBuilder(MainApplication.class); builder.web(false).headless(false).registerShutdownHook(true).run(unused); } catch (Throwable thrown) { log.error("ExampleApplication.main caught an exception.", thrown); } Thread.sleep(Long.MAX_VALUE); System.exit(-9999); }
From source file:kafka.examples.producer.BasicPartitionExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {/*from w w w . j ava2s . co m*/ Namespace res = parser.parseArgs(args); /* parse args */ String brokerList = res.getString("bootstrap.servers"); String topic = res.getString("topic"); Boolean syncSend = res.getBoolean("syncsend"); long noOfMessages = res.getLong("messages"); long delay = res.getLong("delay"); String messageType = res.getString("messagetype"); Properties producerConfig = new Properties(); producerConfig.put("bootstrap.servers", brokerList); producerConfig.put("client.id", "basic-producer"); producerConfig.put("acks", "all"); producerConfig.put("retries", "3"); producerConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); SimpleProducer<byte[], byte[]> producer = new SimpleProducer<>(producerConfig, syncSend); for (int i = 0; i < noOfMessages; i++) { if (i % 2 == 0) producer.send(topic, 0, getKey(i), getEvent(messageType, i)); // send even numbered messages else producer.send(topic, 1, getKey(i), getEvent(messageType, i)); // send odd numbered messages try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } producer.close(); } catch (ArgumentParserException e) { if (args.length == 0) { parser.printHelp(); System.exit(0); } else { parser.handleError(e); System.exit(1); } } }
From source file:com.apipulse.bastion.Main.java
public static void main(String[] args) throws IOException, ClassNotFoundException { log.info("Bastion starting. Loading chains"); final File dir = new File("etc/chains"); final LinkedList<ActorRef> chains = new LinkedList<ActorRef>(); for (File file : dir.listFiles()) { if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) { log.info("Loading chain: " + file.getName()); ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file))); ActorRef ref = BastionActors.getInstance().initChain(config.getName(), Class.forName(config.getQualifiedClass())); Iterator<StageConfig> iterator = config.getStages().iterator(); while (iterator.hasNext()) ref.tell(iterator.next(), null); chains.add(ref);//from w ww . j a va 2 s .c o m } } SpringApplication app = new SpringApplication(); HashSet<Object> objects = new HashSet<Object>(); objects.add(ApiController.class); final ConfigurableApplicationContext context = app.run(ApiController.class, args); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { log.info("Bastion shutting down"); Iterator<ActorRef> iterator = chains.iterator(); while (iterator.hasNext()) iterator.next().tell(new StopMessage(), null); Thread.sleep(2000); context.stop(); log.info("Bastion shutdown complete"); } catch (Exception e) { } } }); }
From source file:edu.vt.middleware.cas.ldap.LoadDriver.java
public static void main(final String[] args) { if (args.length < 4) { System.out.println("USAGE: LoadDriver sample_count thread_count " + "path/to/credentials.csv path/to/spring-context.xml"); return;/*ww w .j a v a2 s . c o m*/ } final int samples = Integer.parseInt(args[0]); final int threads = Integer.parseInt(args[1]); final File credentials = new File(args[2]); if (!credentials.exists()) { throw new IllegalArgumentException(credentials + " does not exist."); } ApplicationContext context; try { context = new ClassPathXmlApplicationContext(args[3]); } catch (BeanDefinitionStoreException e) { if (e.getCause() instanceof FileNotFoundException) { // Try treating path as filesystem path context = new FileSystemXmlApplicationContext(args[3]); } else { throw e; } } final LoadDriver driver = new LoadDriver(samples, threads, credentials, context); System.err.println("Load test configuration:"); System.err.println("\tthreads: " + threads); System.err.println("\tsamples: " + samples); System.err.println("\tcredentials: " + credentials); driver.start(); while (driver.getState().hasWorkRemaining()) { try { Thread.sleep(1000); } catch (InterruptedException e) { } } driver.stop(); }
From source file:edu.stanford.junction.simulator.ResponseTimeSimulator.java
public static void main(String[] argv) { ActivityScript desc = new ActivityScript(); JSONObject platform = new JSONObject(); try {/*from w w w. j a v a 2 s . c om*/ platform.put("android", "http://my.realsitic.url/for_android"); desc.addRolePlatform("simulator", "android", platform); } catch (Exception e) { } Date makeJuncTime = new Date(); XMPPSwitchboardConfig config = new XMPPSwitchboardConfig("prpl.stanford.edu"); JunctionMaker maker = JunctionMaker.getInstance(config); for (int actor_i = NumOfParticipant - 1; actor_i >= 0; actor_i--) { try { maker.newJunction(desc, new SimActorRT(makeJuncTime.getTime(), actor_i)); } catch (JunctionException e) { e.printStackTrace(System.err); } } while (true) { try { Thread.sleep(500000); } catch (Exception e) { } } }
From source file:cspro2sql.Main.java
public static void main(String[] args) { CsPro2SqlOptions opts = getCommandLineOptions(args); boolean error = false; List<Dictionary> dictionaries; try {//from w w w. j av a2s. co m dictionaries = DictionaryReader.parseDictionaries(opts.schema, opts.dictionary, opts.tablePrefix); } catch (Exception e) { opts.ps.close(); opts.printHelp(e.getMessage()); System.exit(1); return; } if (opts.schemaEngine) { error = !SchemaEngine.execute(dictionaries, opts.foreignKeys, opts.ps); } else if (opts.loaderEngine) { if (opts.delay == null) { error = !LoaderEngine.execute(dictionaries, opts.prop, opts.allRecords, opts.checkConstraints, opts.checkOnly, opts.force, opts.recovery, opts.ps); } else { while (true) { try { LoaderEngine.execute(dictionaries, opts.prop, opts.allRecords, opts.checkConstraints, opts.checkOnly, opts.force, opts.recovery, opts.ps); } catch (Exception ex) { System.err.println(ex.getMessage()); } try { Thread.sleep(opts.delay); } catch (Exception ex) { System.err.println(ex.getMessage()); } } } } else if (opts.monitorEngine) { error = !MonitorEngine.execute(dictionaries, opts.ps); } else if (opts.updateEngine) { error = !UpdateEngine.execute(opts.prop); } else if (opts.statusEngine) { error = !StatusEngine.execute(dictionaries, opts.prop); } else if (opts.loadAndUpdate) { while (true) { try { LoaderEngine.execute(dictionaries, opts.prop, opts.allRecords, opts.checkConstraints, opts.checkOnly, opts.force, opts.recovery, opts.ps); UpdateEngine.execute(opts.prop); } catch (Exception ex) { System.err.println(ex.getMessage()); } try { Thread.sleep(opts.delay); } catch (Exception ex) { System.err.println(ex.getMessage()); } } } if (opts.ps != null) { opts.ps.close(); } if (error) { System.exit(1); } }
From source file:davmail.DavGateway.java
/** * Start the gateway, listen on specified smtp and pop3 ports * * @param args command line parameter config file path *///from w w w .j a v a 2s. com public static void main(String[] args) { if (args.length >= 1) { Settings.setConfigFilePath(args[0]); } Settings.load(); DavGatewayTray.init(); start(); // server mode: all threads are daemon threads, do not let main stop if (Settings.getBooleanProperty("davmail.server")) { Runtime.getRuntime().addShutdownHook(new Thread("Shutdown") { @Override public void run() { DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_INTERRUPTED")); DavGateway.stop(); stopped = true; } }); try { while (!stopped) { Thread.sleep(1000); } } catch (InterruptedException e) { DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_INTERRUPTED")); stop(); DavGatewayTray.debug(new BundleMessage("LOG_GATEWAY_STOP")); } } }
From source file:eu.delving.services.MockServices.java
public static void main(String... args) throws InterruptedException { try {/* w w w .j a v a 2 s . c om*/ start(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } Logger.getLogger(MockServices.class).info("Waiting 10 seconds, then kill again"); Thread.sleep(10000); stop(); }