List of usage examples for java.lang Thread start
public synchronized void start()
From source file:ExecDemoPartial.java
public static void main(String argv[]) throws IOException { BufferedReader is; // reader for output of process String line;//from w w w . jav a2 s . c o m final Process p = Runtime.getRuntime().exec(PROGRAM); Thread waiter = new Thread() { public void run() { try { p.waitFor(); } catch (InterruptedException ex) { // OK, just quit this thread. return; } System.out.println("Program terminated!"); done = true; } }; waiter.start(); // getInputStream gives an Input stream connected to // the process p's standard output (and vice versa). We use // that to construct a BufferedReader so we can readLine() it. is = new BufferedReader(new InputStreamReader(p.getInputStream())); while (!done && ((line = is.readLine()) != null)) System.out.println(line); return; }
From source file:httpscheduler.HttpScheduler.java
/** * @param args the command line arguments * @throws java.lang.Exception//from ww w . jav a 2 s .c om */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Invalid command line parameters for worker"); System.exit(-1); } int fixedExecutorSize = 4; //Creating fixed size executor ThreadPoolExecutor taskCommExecutor = new ThreadPoolExecutor(fixedExecutorSize, fixedExecutorSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); // Used for late binding JobMap jobMap = new JobMap(); // Set port number int port = Integer.parseInt(args[0]); // Set worker mode String mode = args[1].substring(2); // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); // Different handlers for late binding and generic cases if (mode.equals("late")) reqistry.register("*", new LateBindingRequestHandler(taskCommExecutor, jobMap)); else reqistry.register("*", new GenericRequestHandler(taskCommExecutor, mode)); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; // create a thread to listen for possible client available connections Thread t; if (mode.equals("late")) t = new LateBindingRequestListenerThread(port, httpService, sf); else t = new GenericRequestListenerThread(port, httpService, sf); System.out.println("Request Listener Thread created"); t.setDaemon(false); t.start(); // main thread should wait for the listener to exit before shutdown the // task executor pool t.join(); // shutdown task executor pool and wait for any taskCommExecutor thread // still running taskCommExecutor.shutdown(); while (!taskCommExecutor.isTerminated()) { } System.out.println("Finished all task communication executor threads"); System.out.println("Finished all tasks"); }
From source file:com.github.lburgazzoli.sandbox.reactor.ProcessorMain.java
public static void main(String[] args) { try {//from w ww . j ava 2 s .co 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:com.mirth.connect.server.launcher.MirthLauncher.java
public static void main(String[] args) { try {//from ww w .j a v a2s. co m try { uninstallPendingExtensions(); installPendingExtensions(); } catch (Exception e) { logger.error("Error uninstalling or installing pending extensions.", e); } Properties mirthProperties = new Properties(); String includeCustomLib = null; try { mirthProperties.load(new FileInputStream(new File(MIRTH_PROPERTIES_FILE))); includeCustomLib = mirthProperties.getProperty(PROPERTY_INCLUDE_CUSTOM_LIB); createAppdataDir(mirthProperties); } catch (Exception e) { logger.error("Error creating the appdata directory.", e); } ManifestFile mirthServerJar = new ManifestFile("server-lib/mirth-server.jar"); ManifestFile mirthClientCoreJar = new ManifestFile("server-lib/mirth-client-core.jar"); ManifestDirectory serverLibDir = new ManifestDirectory("server-lib"); serverLibDir.setExcludes(new String[] { "mirth-client-core.jar" }); List<ManifestEntry> manifestList = new ArrayList<ManifestEntry>(); manifestList.add(mirthServerJar); manifestList.add(mirthClientCoreJar); manifestList.add(serverLibDir); // We want to include custom-lib if the property isn't found, or if it equals "true" if (includeCustomLib == null || Boolean.valueOf(includeCustomLib)) { manifestList.add(new ManifestDirectory("custom-lib")); } ManifestEntry[] manifest = manifestList.toArray(new ManifestEntry[manifestList.size()]); // Get the current server version JarFile mirthClientCoreJarFile = new JarFile(mirthClientCoreJar.getName()); Properties versionProperties = new Properties(); versionProperties.load(mirthClientCoreJarFile .getInputStream(mirthClientCoreJarFile.getJarEntry("version.properties"))); String currentVersion = versionProperties.getProperty("mirth.version"); List<URL> classpathUrls = new ArrayList<URL>(); addManifestToClasspath(manifest, classpathUrls); addExtensionsToClasspath(classpathUrls, currentVersion); URLClassLoader classLoader = new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()])); Class<?> mirthClass = classLoader.loadClass("com.mirth.connect.server.Mirth"); Thread mirthThread = (Thread) mirthClass.newInstance(); mirthThread.setContextClassLoader(classLoader); mirthThread.start(); } catch (Exception e) { e.printStackTrace(); } }
From source file:cache.reverseproxy.CacheableServicesReverseProxy.java
public static void main(final String[] args) throws Exception { int port = 8888; if (args.length > 0) { try {//from ww w.j a v a 2 s .co m port = Integer.parseInt(args[0]); } catch (Exception e) { System.err.println("->Invalid Port!!"); } } final Thread t = new RequestListenerThread(port); t.setDaemon(false); t.start(); }
From source file:thrift.Httpd.java
public static void main(String[] args) throws Exception { if (args.length < 1) { logger.info("No root directory specified. Using working directory."); args = new String[1]; args[0] = "."; }/*from ww w . j a v a2s .co m*/ Thread t = new RequestListenerThread(8088, args[0]); t.setDaemon(false); t.start(); }
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//from w w w. ja 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:com.salaboy.rolo.hardware.test.HardwareSerialTestCommandServer.java
public static void main(String[] args) throws Exception { Weld weld = new Weld(); WeldContainer container = weld.initialize(); HardwareSerialTestCommandServer roloCommandServer = container.instance() .select(HardwareSerialTestCommandServer.class).get(); // create Options object Options options = new Options(); // add t option options.addOption("t", true, "sensors latency"); options.addOption("ip", true, "host"); options.addOption("port", true, "port"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String sensorLatency = cmd.getOptionValue("t"); if (sensorLatency == null) { System.out.println(" The Default Latency will be used: " + defaultLatency); } else {/*from w ww .j a va 2 s.c o m*/ System.out.println(" The Latency will be set to: " + sensorLatency); defaultLatency = new Long(sensorLatency); } String ip = cmd.getOptionValue("ip"); if (ip == null) { System.out.println(" The Default IP will be used: 127.0.0.1"); roloCommandServer.setHost("127.0.0.1"); } else { System.out.println(" The IP will be set to: " + ip); roloCommandServer.setHost(ip); } String port = cmd.getOptionValue("port"); if (port == null) { System.out.println(" The Default Port will be used: 5445"); roloCommandServer.setPort(5445); } else { System.out.println(" The Port will be set to: " + port); roloCommandServer.setPort(Integer.parseInt(port)); } System.out.println("Starting Rolo ..."); Thread thread = new Thread(roloCommandServer); thread.start(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("Shutdown Hook is running !"); } }); }
From source file:com.heliosdecompiler.helios.bootloader.Bootloader.java
public static void main(String[] args) { try {/*from w w w . j a v a2s .c o m*/ if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs()) throw new RuntimeException("Could not create data directory"); if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs()) throw new RuntimeException("Could not create addons directory"); if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile()) throw new RuntimeException("Could not create settings file"); if (Constants.DATA_DIR.isFile()) throw new RuntimeException("Data directory is file"); if (Constants.ADDONS_DIR.isFile()) throw new RuntimeException("Addons directory is file"); if (Constants.SETTINGS_FILE.isDirectory()) throw new RuntimeException("Settings file is directory"); try { Class<?> clazz = Class.forName("org.eclipse.swt.widgets.Event"); Object location = clazz.getProtectionDomain() != null && clazz.getProtectionDomain().getCodeSource() != null ? clazz.getProtectionDomain().getCodeSource().getLocation() : ""; throw new RuntimeException("SWT should not be loaded. Instead, it was loaded from " + location); } catch (ClassNotFoundException ignored) { loadSWTLibrary(); } DisplayPumper displayPumper = new DisplayPumper(); if (System.getProperty("os.name").toLowerCase().contains("mac")) { System.out.println("Attemting to force main thread"); Executor executor; try { Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch"); Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null); executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor") .invoke(dispatchInstance); } catch (Throwable throwable) { throw new RuntimeException("Could not reflectively access Dispatch", throwable); } if (executor != null) { executor.execute(displayPumper); } else { throw new RuntimeException("Could not load executor"); } } else { Thread pumpThread = new Thread(displayPumper); pumpThread.setName("Display Pumper"); pumpThread.start(); } while (!displayPumper.isReady()) ; Display display = displayPumper.getDisplay(); Shell shell = displayPumper.getShell(); Splash splashScreen = new Splash(display); splashScreen.updateState(BootSequence.CHECKING_LIBRARIES); checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION, BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY); checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION, BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU); try { if (!System.getProperty("os.name").toLowerCase().contains("linux")) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception exception) { //Not important. No point notifying the user } Helios.main(args, shell, splashScreen); synchronized (displayPumper.getSynchronizer()) { displayPumper.getSynchronizer().wait(); } System.exit(0); } catch (Throwable t) { displayError(t); System.exit(1); } }
From source file:com.jivesoftware.os.amza.service.AmzaGetStress.java
public static void main(String[] args) throws IOException { args = new String[] { "soa-integ-data11.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 < 1024; i++) { final String rname = partitionName + i; final org.apache.http.client.HttpClient httpClient = HttpClients.createDefault(); Thread t = new Thread() { @Override/*from w ww.ja v a 2 s .c o m*/ public void run() { try { get(httpClient, hostName, port, rname, 0, count, batchSize); } catch (Exception x) { x.printStackTrace(); } } }; t.start(); } }