List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:WaitComm.java
public static void main(String args[]) { WFlagSend s = new WFlagSend(); WFlagRec r = new WFlagRec(s); Thread st = new Thread(s); Thread rt = new Thread(r); rt.setDaemon(true);/*from ww w . j a va 2 s. co m*/ st.start(); rt.start(); try { st.join(); while (s.isValid) { Thread.sleep(100); } } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:net.sf.janos.Janos.java
/** * @param args/*from w w w . j a v a 2s . c om*/ * @throws Exception */ public static void main(String[] args) { if (args.length > 1) { System.out.println("Usage: Janos [port]"); System.exit(1); } if (args.length == 1) { System.setProperty("net.sbbi.upnp.Discovery.bindPort", args[0]); } /* * [DW] For some reason unknown to me, given: * 1) arch is intel * 2) os is Mac OS X * 3) running in eclipse * 4) using SWT * no exceptions are displayed in the eclipse console in the main thread. * To work around this, we just do everything in a new thread :-) */ if (Boolean.getBoolean("net.sf.janos.forkNewThread")) { try { Thread mainThread = new Thread(new Janos(), "Janos-SWT"); mainThread.start(); mainThread.join(); } catch (Throwable t) { LogFactory.getLog(Janos.class).fatal("Could not start thread: ", t); System.exit(1); } } else { new Janos().run(); } }
From source file:MainClass.java
public static void main(String[] args) { Thread first = new TryThread("A ", "a ", 200L); Thread second = new TryThread("B ", "b ", 300L); Thread third = new TryThread("C ", "c ", 500L); first.start();/* ww w.j a v a2 s . com*/ second.start(); third.start(); try { first.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("Executing " + t.getName()); t.start();/*from ww w . j a va 2 s. c o m*/ if (!t.isInterrupted()) { t.interrupt(); } try { t.join(); } catch (InterruptedException e) { } }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("Executing " + t.getName()); t.start();//from w w w . j av a 2s.c o m if (!t.interrupted()) { t.interrupt(); } // block until other threads finish try { t.join(); } catch (InterruptedException e) { } }
From source file:Main.java
public static void main(String[] args) throws Exception { Thread thread1 = new Thread(new TestThread(1)); Thread thread2 = new Thread(new TestThread(2)); thread1.setPriority(Thread.MAX_PRIORITY); thread2.setPriority(Thread.MIN_PRIORITY); thread1.start();/* www . j a v a 2 s .c om*/ thread2.start(); thread1.join(); thread2.join(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Runner t = new Runner(); Thread t1 = new Thread(t); for (int i = 0; i < 50; i++) { t.queue.add(i);//w w w . ja v a 2 s .c o m } System.out.println(("Number of items in queue: " + t.queue.size())); t1.start(); Thread.sleep(1000); t1.interrupt(); t1.join(); System.out.println(("Number of items in queue: " + t.queue.size())); System.out.println(("Joined t1. Finished")); }
From source file:info.bitoo.Main.java
public static void main(String[] args) throws InterruptedException, IOException, NoSuchAlgorithmException, ClientAdapterException { CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/*from w ww . ja v a 2s . co m*/ try { cmd = parser.parse(createCommandLineOptions(), args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); } Properties props = readConfiguration(cmd); BiToo biToo = new BiToo(props); URL torrentURL = null; if (cmd.hasOption("f")) { String parmValue = cmd.getOptionValue("f"); String torrentName = parmValue + ".torrent"; biToo.setTorrent(torrentName); } else if (cmd.hasOption("t")) { torrentURL = new URL(cmd.getOptionValue("t")); biToo.setTorrent(torrentURL); } else { return; } try { Thread main = new Thread(biToo); main.setName("BiToo"); main.start(); //wait until thread complete main.join(); } finally { biToo.destroy(); } if (biToo.isCompleted()) { System.out.println("Download completed"); System.exit(0); } else { System.out.println("Download failed"); System.exit(1); } }
From source file:jms.Main.java
public static void main(String[] args) throws NamingException, JMSException, FileNotFoundException, InterruptedException, ParseException, CloneNotSupportedException { Options options = createOptions();// w ww. j ava 2 s. c o m CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args, false); Histogram latencyHist = Main.metrics.histogram(name(ConsumerThread.class, "global", "consumer", "latency")); Meter consumerRate = Main.metrics.meter(name(ConsumerThread.class, "global", "consumer", "rate")); if (cmd.hasOption("c")) { CONFIG_FILE_PATH = cmd.getOptionValue("c"); } else { CONFIG_FILE_PATH = System.getProperty("user.dir") + "/src/main/resources/client.yaml"; } TestConfiguration config = ConfigReader.parseConfig(CONFIG_FILE_PATH); // System.setProperty("qpid.flow_control_wait_failure", "1500000"); // Subscribers startStatReporting(config.getGlobalConfig()); int subscriberCount = config.getTopicSubscriberConfigList().size() + config.getQueueSubscriberConfigList().size() + config.getDurableSubscriberConfigList().size(); final List<Thread> threadList = new ArrayList<Thread>(subscriberCount); TestTopicSubscriber topicSubscriber; for (SubscriberConfig subscriberConfig : config.getTopicSubscriberConfigList()) { topicSubscriber = new TestTopicSubscriber(); topicSubscriber.subscribe(subscriberConfig); Thread subThread = new Thread(new ConsumerThread(topicSubscriber, latencyHist, consumerRate)); subThread.start(); threadList.add(subThread); } SimpleJMSConsumer queueReceiver; for (SubscriberConfig subscriberConfig : config.getQueueSubscriberConfigList()) { queueReceiver = new TestQueueReceiver(); queueReceiver.subscribe(subscriberConfig); Thread subThread = new Thread(new ConsumerThread(queueReceiver, latencyHist, consumerRate)); subThread.start(); threadList.add(subThread); } TestDurableTopicSubscriber durableTopicSubscriber; for (SubscriberConfig subscriberConfig : config.getDurableSubscriberConfigList()) { durableTopicSubscriber = new TestDurableTopicSubscriber(); durableTopicSubscriber.subscribe(subscriberConfig); Thread subThread = new Thread(new ConsumerThread(durableTopicSubscriber, latencyHist, consumerRate)); subThread.start(); threadList.add(subThread); } // Publishers TestTopicPublisher topicPublisher; for (PublisherConfig publisherConfig : config.getTopicPublisherList()) { topicPublisher = new TestTopicPublisher(); topicPublisher.init(publisherConfig); Thread pubThread = new Thread(new PublisherThread(topicPublisher)); pubThread.start(); threadList.add(pubThread); } TestQueueSender queuePublisher; for (PublisherConfig publisherConfig : config.getQueuePublisherConfigList()) { queuePublisher = new TestQueueSender(); queuePublisher.init(publisherConfig); Thread pubThread = new Thread(new PublisherThread(queuePublisher)); pubThread.start(); threadList.add(pubThread); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { log.info("Shutting down test client."); slf4jReporter.report(); csvGaugeReporter.report(); reporter.report(); if (null != jmxReporter) { jmxReporter.close(); } if (null != csvReporter) { csvReporter.report(); csvReporter.close(); } for (Thread t : threadList) { t.interrupt(); } } }); // barrier. wait till all the done for (Thread thread : threadList) { thread.join(); } log.info("Test Complete!"); }
From source file:Main.java
public static void main(String[] args) throws Exception { Thread previousThread = null; for (int i = 0; i < 20; i++) { JobRunnable job = new JobRunnable(i, previousThread); Thread thread = new Thread(job, "T-" + i); thread.start();/* w w w .j a v a 2 s .c o m*/ previousThread = thread; } if (previousThread != null) { previousThread.join(); } System.out.println("Program done."); }