List of usage examples for java.lang Thread start
public synchronized void start()
From source file:com.ariatemplates.attester.junit.StreamRedirector.java
public static void redirectStream(final InputStream inputStream, final OutputStream outputStream) { Thread thread = new Thread(new Runnable() { public void run() { try { IOUtils.copy(inputStream, outputStream); } catch (IOException e) { e.printStackTrace();//from w w w . j a v a2 s .c o m } } }); thread.setDaemon(false); thread.start(); }
From source file:io.dropwizard.websockets.DropWizardWebsocketsTest.java
@BeforeClass public static void setUpClass() throws InterruptedException, IOException { CountDownLatch serverStarted = new CountDownLatch(1); Thread serverThread = new Thread(GeneralUtils.rethrow(() -> new MyApp(serverStarted) .run(new String[] { "server", Resources.getResource("server.yml").getPath() }))); serverThread.setDaemon(true);/*from w w w.j a v a2s. co m*/ serverThread.start(); serverStarted.await(10, SECONDS); }
From source file:com.liferay.alerts.test.AlertFactory.java
protected static void notify(final Context context, final List<Alert> alerts) { Thread thread = new Thread(new Runnable() { @Override/*from www.j a v a2 s . c o m*/ public void run() { NotificationUtil.notify(context, alerts); } }); thread.start(); }
From source file:com.mashape.client.http.HttpClient.java
public static <T> Thread doRequest(Class<T> clazz, HttpMethod httpMethod, String url, Map<String, Object> parameters, ContentType contentType, ResponseType responseType, List<Authentication> authenticationHandlers, MashapeCallback<T> callback) { Thread t = new HttpRequestThread<T>(clazz, httpMethod, url, parameters, contentType, responseType, authenticationHandlers, callback); t.start(); return t;//from w ww. j a v a 2s .c o m }
From source file:com.srikanthps.HbaseBenchmarking.java
private static void runTest(Class rowCreatorClass, long startingRowKey, int numRecordsToInsert, long numThreadsToUse, String data) throws InterruptedException, InstantiationException, IllegalAccessException { timingStats.clear();// w ww. j ava2 s .c o m int numRecordsPerThread = (int) Math.ceil(((double) numRecordsToInsert) / numThreadsToUse); List<Thread> threads = new ArrayList<Thread>(); for (int i = 0; i < numThreadsToUse; i++) { RowCreator c = (RowCreator) rowCreatorClass.newInstance(); c.setData(data); c.setNextRowkey(startingRowKey); c.setNumRecordsToInsert(numRecordsPerThread); Thread t = new Thread(c); threads.add(t); t.start(); } for (int i = 0; i < numThreadsToUse; i++) { threads.get(i).join(); } System.out.println(StringUtils.rightPad(rowCreatorClass.newInstance().toString(), 50) + "," + format(numThreadsToUse, VALUE_LEFT_PAD) + "," + format(timingStats.getN(), VALUE_LEFT_PAD) + "," + format(timingStats.getMean(), VALUE_LEFT_PAD) + "," + format(timingStats.getStandardDeviation(), VALUE_LEFT_PAD) + "," + format(timingStats.getMax(), VALUE_LEFT_PAD) + "," + format(timingStats.getMin(), VALUE_LEFT_PAD) + "," + format(timingStats.getPercentile(80.0), VALUE_LEFT_PAD) + "," + format(timingStats.getPercentile(90.0), VALUE_LEFT_PAD)); }
From source file:Main.java
public static void waitForMillis(final int millis, Context context) { Thread thread = new Thread() { @Override//from www. j a v a2s . c o m public void run() { try { synchronized (this) { wait(millis); } } catch (InterruptedException ex) { } // TODO } }; thread.start(); }
From source file:immf.growl.GrowlNotifier.java
public static GrowlNotifier getInstance(GrowlApiClient clientConcrete, Config config) { if (clientConcrete != null && config != null) { GrowlNotifier notify = new GrowlNotifier(); notify.client = clientConcrete;//from w ww.ja va 2 s .com notify.config = config; String apiKey = clientConcrete.getApiKeyFromConfig(config); if (apiKey != null && apiKey != "") { String[] apiKeyArray = apiKey.split(","); for (String key : apiKeyArray) { notify.growlApiKeyList.add(new GrowlKey(key)); } if (notify.growlApiKeyList.size() > 0) { notify.client = clientConcrete; Thread t = new Thread(notify); t.setName(notify.client.getClass().getName()); t.setDaemon(true); t.start(); } } return notify; } else { return null; } }
From source file:cosmos.results.integration.CosmosIntegrationSetup.java
public static void loadAllWikis() throws Exception { List<Thread> threads = Lists.newArrayList(); threads.add(new Thread(new Runnable() { public void run() { try { CosmosIntegrationSetup.getWiki1(); } catch (Exception e) { throw new RuntimeException(e); }/*from w ww . j a v a 2s . c o m*/ } })); threads.add(new Thread(new Runnable() { public void run() { try { CosmosIntegrationSetup.getWiki2(); } catch (Exception e) { throw new RuntimeException(e); } } })); threads.add(new Thread(new Runnable() { public void run() { try { CosmosIntegrationSetup.getWiki3(); } catch (Exception e) { throw new RuntimeException(e); } } })); threads.add(new Thread(new Runnable() { public void run() { try { CosmosIntegrationSetup.getWiki4(); } catch (Exception e) { throw new RuntimeException(e); } } })); threads.add(new Thread(new Runnable() { public void run() { try { CosmosIntegrationSetup.getWiki5(); } catch (Exception e) { throw new RuntimeException(e); } } })); for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } }
From source file:dk.netarkivet.common.utils.ProcessUtils.java
/** Collect all output from an inputstream, appending it to a file. * This will eventually close the given InputStream, * but not necessarily before the method returns. The thread created * is placed in a thread set, and should be removed once all output * has been collected.//from w w w . j a v a 2 s.c o m * * @param inputStream The inputstream to read contents from * @param outputFile The file that output should be appended to. * @param collectionThreads Set of threads that concurrently collect output */ public static void writeProcessOutput(final InputStream inputStream, final File outputFile, Set<Thread> collectionThreads) { final OutputStream stream; try { stream = new FileOutputStream(outputFile, true); } catch (FileNotFoundException e) { throw new IOFailure("Cannot create file '" + outputFile + " to write process output to.", e); } Thread t = makeCollectorThread(inputStream, stream, -1); t.start(); collectionThreads.add(t); }
From source file:dk.netarkivet.common.utils.ProcessUtils.java
/** Collect all output from an inputstream, up to maxCollect bytes, * in an output object. This will eventually close the given InputStream, * but not necessarily before the method returns. The thread created * is placed in a thread set, and should be removed once all output * has been collected. While only a limited amount may be written to * the output object, the entire output will be read from the inputStream * unless the thread or the inputStream is destroyed first. * * @param inputStream The inputstream to read contents from * @param maxCollect The maximum number of bytes to collect, or -1 for no * limit/* w w w . j a va 2 s . c o m*/ * @param collectionThreads Set of threads that concurrently collect output * @return An object that collects the output. Once the thread returned * is finished, the object will no longer be written to. The collected * output can be retrieved with the toString method. */ public static Object collectProcessOutput(final InputStream inputStream, final int maxCollect, Set<Thread> collectionThreads) { final OutputStream stream = new ByteArrayOutputStream(); Thread t = makeCollectorThread(inputStream, stream, maxCollect); t.start(); collectionThreads.add(t); return stream; }