List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:BestReplacement.java
public static void main(String[] args) { try {/*from www.j a v a 2 s. co m*/ BestReplacement br = new BestReplacement(); System.out.println(" just created, br.isAlive()=" + br.isAlive()); Thread.sleep(4200); long startTime = System.currentTimeMillis(); br.suspendRequest(); System.out.println(" just submitted a suspendRequest"); boolean suspensionTookEffect = br.waitForActualSuspension(10000); long stopTime = System.currentTimeMillis(); if (suspensionTookEffect) { System.out.println(" the internal thread took " + (stopTime - startTime) + " ms to notice " + "\n the suspend request and is now " + "suspended."); } else { System.out.println(" the internal thread did not notice " + "the suspend request " + "\n within 10 seconds."); } Thread.sleep(5000); br.resumeRequest(); System.out.println("Submitted a resumeRequest"); Thread.sleep(2200); br.stopRequest(); System.out.println("Submitted a stopRequest"); } catch (InterruptedException x) { // ignore } }
From source file:FullScreen.java
public static void main(String args[]) { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice(); DisplayMode originalDisplayMode = graphicsDevice.getDisplayMode(); try {/*from w w w . ja v a 2 s . c o m*/ Frame frame = new Frame(); frame.setUndecorated(true); frame.setIgnoreRepaint(true); graphicsDevice.setFullScreenWindow(frame); if (graphicsDevice.isDisplayChangeSupported()) { graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice)); } frame.createBufferStrategy(2); // 2 buffers Rectangle bounds = frame.getBounds(); BufferStrategy bufferStrategy = frame.getBufferStrategy(); while (!done()) { Graphics g = null; try { g = bufferStrategy.getDrawGraphics(); if ((counter <= 2)) { // 2 buffers g.setColor(Color.CYAN); g.fillRect(0, 0, bounds.width, bounds.height); } g.setColor(Color.RED); // redraw prior line, too, since 2 buffers if (counter != 1) { g.drawLine(counter - 1, (counter - 1) * 5, bounds.width, bounds.height); } g.drawLine(counter, counter * 5, bounds.width, bounds.height); bufferStrategy.show(); } finally { if (g != null) { g.dispose(); } } try { Thread.sleep(250); } catch (InterruptedException ignored) { } } } finally { graphicsDevice.setDisplayMode(originalDisplayMode); graphicsDevice.setFullScreenWindow(null); } System.exit(0); }
From source file:com.continuuity.loom.common.queue.internal.ElementsTrackingQueueCliTool.java
public static void main(String[] args) throws Exception { ElementsTrackingQueueCliTool client = null; try {/*w ww . j a v a2 s .c om*/ client = new ElementsTrackingQueueCliTool(); client.configure(args); } catch (ParseException e) { printHelp(); return; } catch (Throwable e) { printHelp(); // to divide usage from stacktrace output. It's lame, yes. Thread.sleep(10); System.out.println("ERROR"); e.printStackTrace(); return; } client.execute(); }
From source file:co.paralleluniverse.galaxy.Server.java
/** * Runs the Galaxy server.//from w w w . j ava2 s .c o m * If command line arguments are given, the first {@code args[0]} is the path xml (spring) configuration file * and the second (if it exists) is the path to a properties file (referenced in the config-file). * @param args the command line arguments */ public static void main(String[] args) throws Exception { final String configFile = args.length > 0 ? args[0] : null; final String propertiesFile = args.length > 1 ? args[1] : null; start(configFile, propertiesFile); Thread.sleep(Long.MAX_VALUE); }
From source file:de.erdesignerng.visual.ERDesigner.java
public static void main(String[] args) throws IllegalAccessException, TransformerException, IOException, ParserConfigurationException, SAXException { String theFilenameToOpen = null; if (args != null) { for (String theArgument : args) { LOGGER.info("Was called with argument :" + theArgument); }/* ww w .j a v a2s.c om*/ // In WebStart mode or standalone, there can be two options // -open <filename> // -print <filename> if (args.length == 2) { if ("-open".equals(args[0]) || "-print".equals(args[0])) { theFilenameToOpen = args[1]; } } } // Disable D3D rendering pipeline System.setProperty("sun.java2d.d3d", "false"); //Show LOGO DefaultSplashScreen theScreen = new DefaultSplashScreen("/de/erdesignerng/splashscreen.jpg"); theScreen.setVisible(true); DataTypeIO.getInstance().loadUserTypes(); final ERDesignerMainFrame frame = new ERDesignerMainFrame(); frame.setModel(frame.createNewModel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { Thread.sleep(1000); } catch (InterruptedException e) { // Just wait here :-) } theScreen.setVisible(false); frame.setVisible(true); if (StringUtils.isNotEmpty(theFilenameToOpen)) { frame.commandOpenFile(new File(theFilenameToOpen)); } }
From source file:com.senseidb.search.node.inmemory.InMemoryIndexPerfEval.java
public static void main(String[] args) throws Exception { final InMemorySenseiService memorySenseiService = InMemorySenseiService.valueOf( new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("test-conf/node1/").toURI())); final List<JSONObject> docs = new ArrayList<JSONObject>(15000); LineIterator lineIterator = FileUtils.lineIterator( new File(InMemoryIndexPerfEval.class.getClassLoader().getResource("data/test_data.json").toURI())); int i = 0;/*from w w w. j a v a 2s . c o m*/ while (lineIterator.hasNext() && i < 100) { String car = lineIterator.next(); if (car != null && car.contains("{")) docs.add(new JSONObject(car)); i++; } Thread[] threads = new Thread[10]; for (int k = 0; k < threads.length; k++) { threads[k] = new Thread(new Runnable() { public void run() { long time = System.currentTimeMillis(); //System.out.println("Start thread"); for (int j = 0; j < 1000; j++) { //System.out.println("Send request"); memorySenseiService.doQuery(getRequest(), docs); } System.out.println("time = " + (System.currentTimeMillis() - time)); } }); threads[k].start(); } Thread.sleep(500000); }
From source file:com.reversemind.glia.other.spring.GliaServerSpringContextLoader.java
public static void main(String... args) throws InterruptedException { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "META-INF/hypergate-server-context.xml"); ServerFactory.Builder builderAdvertiser = applicationContext.getBean("serverBuilderAdvertiser", ServerFactory.Builder.class); LOG.debug("--------------------------------------------------------"); LOG.debug("Builder properties:"); LOG.debug("Name:" + builderAdvertiser.getName()); LOG.debug("Instance Name:" + builderAdvertiser.getInstanceName()); LOG.debug("port:" + builderAdvertiser.getPort()); LOG.debug("isAutoSelectPort:" + builderAdvertiser.isAutoSelectPort()); LOG.debug("Type:" + builderAdvertiser.getType()); LOG.debug("Zookeeper connection string:" + builderAdvertiser.getZookeeperHosts()); LOG.debug("Zookeeper base path:" + builderAdvertiser.getServiceBasePath()); IHyperGateServer server = builderAdvertiser.build(); LOG.debug("\n\n"); LOG.debug("--------------------------------------------------------"); LOG.debug("After server initialization - properties"); LOG.debug("\n"); LOG.debug("Server properties:"); LOG.debug("......"); LOG.debug("Name:" + server.getName()); LOG.debug("Instance Name:" + server.getInstanceName()); LOG.debug("port:" + server.getPort()); server.start();//from w w w . j av a2 s .co m Thread.sleep(60000); server.shutdown(); ServerFactory.Builder builderSimple = (ServerFactory.Builder) applicationContext .getBean("serverBuilderSimple"); LOG.debug("" + builderSimple.port()); IHyperGateServer serverSimple = builderSimple.setAutoSelectPort(true).setName("N A M E").setPort(8000) .setPayloadWorker(new IPayloadProcessor() { @Override public Map<Class, Class> getPojoMap() { return null; } @Override public void setPojoMap(Map<Class, Class> map) { } @Override public void setEjbMap(Map<Class, String> map) { } @Override public void registerPOJO(Class interfaceClass, Class pojoClass) { } @Override public Payload process(Object payloadObject) { return null; } }).build(); LOG.debug("\n\n"); LOG.debug("--------------------------------------------------------"); LOG.debug("Simple Glia server"); LOG.debug("\n"); LOG.debug("Server properties:"); LOG.debug("......"); LOG.debug("Name:" + serverSimple.getName()); LOG.debug("Instance Name:" + serverSimple.getInstanceName()); LOG.debug("port:" + serverSimple.getPort()); }
From source file:com.clustercontrol.winsyslog.HinemosWinSyslogMain.java
public static void main(String[] args) { try {/* w w w . j a v a 2s .c o m*/ log.info("receiver started."); // ?? String etcDir = System.getProperty("hinemos.manager.etc.dir"); String configFilePath = new File(etcDir, "syslog.conf").getAbsolutePath(); WinSyslogConfig.init(configFilePath); // Sender? String targetValue = WinSyslogConfig.getProperty("syslog.send.targets"); log.info("Sender initialise." + " (target=" + targetValue + ")"); UdpSender.init(targetValue); // Receiver boolean tcpEnable = WinSyslogConfig.getBooleanProperty("syslog.receive.tcp"); boolean udpEnable = WinSyslogConfig.getBooleanProperty("syslog.receive.udp"); int port = WinSyslogConfig.getIntegerProperty("syslog.receive.port"); log.info("Receiver starting." + " (tcpEnable=" + tcpEnable + ", udpEnable=" + udpEnable + ", port=" + port + ")"); receiver = new SyslogReceiver(tcpEnable, udpEnable, port); receiver.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { synchronized (shutdownLock) { receiver.shutdown(); shutdown = true; shutdownLock.notify(); } } }); synchronized (shutdownLock) { while (!shutdown) { try { shutdownLock.wait(); } catch (InterruptedException e) { log.warn("shutdown lock interrupted.", e); try { Thread.sleep(1000); } catch (InterruptedException sleepE) { } ; } } } System.exit(0); } catch (Exception e) { log.error("unknown error.", e); } }
From source file:edu.kit.dama.transfer.client.impl.GUIUploadClient.java
/** * The main entry point// w ww. ja va2 s . c om * * @param args The command line argument array */ public static void main(String[] args) { int result = 0; AbstractFile.setCheckLevel(AbstractFile.CHECK_LEVEL.COARSE); GUIUploadClient client; try { client = new GUIUploadClient(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:kafka.examples.producer.CustomPartitionerExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {/* ww w .j a v a 2s .c om*/ 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"); producerConfig.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, "kafka.examples.producer.CustomPartitioner"); SimpleProducer<byte[], byte[]> producer = new SimpleProducer<>(producerConfig, syncSend); for (int i = 0; i < noOfMessages; i++) { producer.send(topic, getKey(i), getEvent(messageType, i)); 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); } } }