List of usage examples for java.lang Thread Thread
public Thread()
From source file:com.semsaas.utils.anyurl.App.java
public static void main(String[] rawArgs) throws Exception { Properties props = new Properties(); String args[] = processOption(rawArgs, props); String outputFile = props.getProperty("output"); OutputStream os = outputFile == null ? System.out : new FileOutputStream(outputFile); final org.apache.camel.spring.Main main = new org.apache.camel.spring.Main(); main.setApplicationContextUri("classpath:application.xml"); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { main.stop();/* w ww .j a v a 2s.co m*/ } catch (Exception e) { } } }); if (args.length > 0) { main.start(); if (main.isStarted()) { CamelContext camelContext = main.getCamelContexts().get(0); String target = rewriteEndpoint(args[0]); boolean producerBased = checkProducerBased(target); InputStream is = null; if (producerBased) { ProducerTemplate producer = camelContext.createProducerTemplate(); is = producer.requestBody(target, null, InputStream.class); } else { ConsumerTemplate consumer = camelContext.createConsumerTemplate(); is = consumer.receiveBody(target, InputStream.class); } IOUtils.copy(is, os); main.stop(); } else { System.err.println("Couldn't trigger jobs, camel wasn't started"); } } else { logger.info("No triggers. Running indefintely"); } }
From source file:com.hortonworks.minicluster.StartMiniHadoopCluster.java
/** * MAKE SURE to start with enough memory -Xmx2048m -XX:MaxPermSize=256 * * Will start a two node Hadoop DFS/YARN cluster * *//*from w ww . ja va 2 s . c o m*/ public static void main(String[] args) throws Exception { System.out.println("=============== Starting YARN/HDFS MINI CLUSTER ==============="); int nodeCount = 2; logger.info("Starting with " + nodeCount + " nodes"); final MiniHadoopCluster yarnCluster = new MiniHadoopCluster("MINI_YARN_CLUSTER", nodeCount); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { yarnCluster.stop(); System.out.println("=============== Stopped YARN/HDFS MINI CLUSTER ==============="); } }); try { yarnCluster.start(); System.out.println("######## MINI CLUSTER started on " + new Date() + ". ########"); System.out.println("\t - YARN log and work directories are available in target/MINI_YARN_CLUSTER"); System.out.println("\t - DFS log and work directories are available in target/MINI_DFS_CLUSTER"); } catch (Exception e) { // won't actually shut down process. Need to see what's going on logger.error("Failed to start mini cluster", e); yarnCluster.close(); } }
From source file:adapter.tdb.sync.clients.GetVocabularyOfMagicDrawAdapterAndPushToStore.java
public static void main(String[] args) { Thread thread = new Thread() { public void start() { URI vocabURI = URI.create("http://localhost:8080/oslc4jmagicdraw/services/sysml-rdfvocabulary"); // create an empty RDF model Model model = ModelFactory.createDefaultModel(); // use FileManager to read OSLC Resource Shape in RDF // String inputFileName = "file:C:/Users/Axel/git/EcoreMetamodel2OSLCSpecification/EcoreMetamodel2OSLCSpecification/Resource Shapes/Block.rdf"; // String inputFileName = "file:C:/Users/Axel/git/ecore2oslc/EcoreMetamodel2OSLCSpecification/RDF Vocabulary/sysmlRDFVocabulary of OMG.rdf"; // InputStream in = FileManager.get().open(inputFileName); // if (in == null) { // throw new IllegalArgumentException("File: " + inputFileName // + " not found"); // } // create TDB dataset String directory = TriplestoreUtil.getTriplestoreLocation(); Dataset dataset = TDBFactory.createDataset(directory); Model tdbModel = dataset.getDefaultModel(); try { HttpGet httpget = new HttpGet(vocabURI); httpget.addHeader("accept", "application/rdf+xml"); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpResponse response = httpClient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = entity.getContent(); model.read(inputStream, null); tdbModel.add(model); }// w ww . j a v a 2 s .c o m } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } tdbModel.close(); dataset.close(); } }; thread.start(); try { thread.join(); System.out.println("Vocabulary of OSLC MagicDraw SysML adapter added to triplestore"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.eclipse.swt.snippets.Snippet304.java
public static void main(String[] args) { display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 304"); shell.setLayout(new GridLayout()); Text text = new Text(shell, SWT.MULTI | SWT.BORDER); text.setText("< cursor was there\na\nmulti\nline\ntext\nnow it's here >"); text.addKeyListener(new KeyListener() { @Override//from w ww .java 2 s . c om public void keyPressed(KeyEvent e) { System.out.println("KeyDown " + e); } @Override public void keyReleased(KeyEvent e) { System.out.println("KeyUp " + e); } }); shell.pack(); shell.open(); /* * Simulate the (platform specific) key sequence * to move the I-beam to the end of a text control. */ new Thread() { @Override public void run() { int key = SWT.END; String platform = SWT.getPlatform(); if (platform.equals("cocoa")) { key = SWT.ARROW_DOWN; } postEvent(SWT.MOD1, SWT.KeyDown); postEvent(key, SWT.KeyDown); postEvent(key, SWT.KeyUp); postEvent(SWT.MOD1, SWT.KeyUp); } }.start(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:net.brtly.monkeyboard.MonkeyBoard.java
public static void main(String[] args) { // configure logging BasicConfigurator.configure();//from ww w.j av a 2 s.c o m _prefs = new Configuration(); initLogging(); LOG.info("Monkey Board v0.1"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { AndroidDebugBridge.terminate(); LOG.debug("[finished]"); } }); createAndShowGui(); }
From source file:DataTypePrintTest.java
public static void main(String[] args) { Thread objectData = new Thread(); String stringData = "Java Mania"; char[] charArrayData = { 'a', 'b', 'c' }; int integerData = 4; long longData = Long.MIN_VALUE; float floatData = Float.MAX_VALUE; double doubleData = Math.PI; boolean booleanData = true; System.out.println(objectData); System.out.println(stringData); System.out.println(charArrayData); System.out.println(integerData); System.out.println(longData); System.out.println(floatData); System.out.println(doubleData); System.out.println(booleanData); }
From source file:com.ideabase.repository.server.RepositoryServerMain.java
public static void main(String[] pArgs) throws InterruptedException { System.err.println("Starting Repository Server at " + new Date()); setupApplicationLogger();/*from w w w .j a va 2 s . c o m*/ setupRequiredSystemProperties(); final RepositoryServerMain repositoryServerMain = new RepositoryServerMain(); if (repositoryServerMain.mRepositoryServer.start()) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Stopping repository server."); repositoryServerMain.mRepositoryServer.stop(); System.out.println("Stopping repository server stopped."); } }); Thread.currentThread().join(); } }
From source file:fr.jetoile.hadoopunit.HadoopStandaloneBootstrap.java
public static void main(String[] args) throws BootstrapException { try {//w ww. j a v a2s . c o m configuration = new PropertiesConfiguration("hadoop.properties"); } catch (ConfigurationException e) { throw new BootstrapException("bad config", e); } HadoopBootstrap bootstrap = HadoopBootstrap.INSTANCE; bootstrap.componentsToStart = bootstrap.componentsToStart.stream() .filter(c -> configuration.containsKey(c.getName().toLowerCase()) && configuration.getBoolean(c.getName().toLowerCase())) .collect(Collectors.toList()); bootstrap.componentsToStop = bootstrap.componentsToStop.stream() .filter(c -> configuration.containsKey(c.getName().toLowerCase()) && configuration.getBoolean(c.getName().toLowerCase())) .collect(Collectors.toList()); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { LOGGER.info("All services are going to be stopped"); bootstrap.stopAll(); } }); bootstrap.startAll(); }
From source file:com.jivesoftware.os.amza.service.AmzaSetStress.java
public static void main(String[] args) throws IOException { args = new String[] { "soa-integ-data12.phx1.jivehosted.com", "1185", "1", "10000" }; final String hostName = args[0]; final int port = Integer.parseInt(args[1]); final int firstDocId = Integer.parseInt(args[2]); final int count = Integer.parseInt(args[3]); final int batchSize = 100; String partitionName = "lorem"; for (int i = 0; i < 8; i++) { final String rname = partitionName + i; final org.apache.http.client.HttpClient httpClient = HttpClients.createDefault(); Thread t = new Thread() { @Override//w ww. j a v a 2 s. c o m public void run() { try { feed(httpClient, hostName, port, rname, 0, count, batchSize); } catch (Exception x) { x.printStackTrace(); } } }; t.start(); } }
From source file:org.eclipse.swt.snippets.Snippet268.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 268"); shell.setLayout(new FillLayout()); StyledText styledText = new StyledText(shell, SWT.V_SCROLL); String multiLineString = ""; for (int i = 0; i < 200; i++) { multiLineString = multiLineString.concat("This is line number " + i + " in the multi-line string.\n"); }//from w w w . j av a2 s .c o m styledText.setText(multiLineString); shell.setSize(styledText.computeSize(SWT.DEFAULT, 400)); shell.open(); // move cursor over styled text Rectangle clientArea = shell.getClientArea(); Point location = shell.getLocation(); Event event = new Event(); event.type = SWT.MouseMove; event.x = location.x + clientArea.width / 2; event.y = location.y + clientArea.height / 2; display.post(event); styledText.addListener(SWT.MouseWheel, e -> System.out.println("Mouse Wheel event " + e)); new Thread() { Event event; @Override public void run() { for (int i = 0; i < 50; i++) { event = new Event(); event.type = SWT.MouseWheel; event.detail = SWT.SCROLL_LINE; event.count = -2; if (!display.isDisposed()) display.post(event); try { Thread.sleep(100); } catch (InterruptedException e) { } } } }.start(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }