List of usage examples for java.lang Thread start
public synchronized void start()
From source file:Main.java
/** Start all given threads and wait on each of them until all are done. * From Stephan Preibisch's Multithreading.java class. See: * http://repo.or.cz/w/trakem2.git?a=blob;f=mpi/fruitfly/general/MultiThreading.java;hb=HEAD * @param threads /*from w ww . java 2 s .co m*/ */ public static void startAndJoin(Thread[] threads) { for (Thread thread : threads) { thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } try { for (Thread thread : threads) { thread.join(); } } catch (InterruptedException ie) { throw new RuntimeException(ie); } }
From source file:Main.java
public static void run(Runnable runnable, String threadName, boolean daemon) { Thread thread = new Thread(runnable, threadName); thread.setName(threadName);/*from w w w .ja va 2s . c om*/ thread.setDaemon(daemon); thread.start(); }
From source file:com.bjorsond.android.timeline.sync.ServerDeleter.java
private static void sendDeleteRequestTOGAEServer(String string, final HttpHost targetHost, final HttpDelete httpDelete) { Runnable sendRunnable = new Runnable() { public void run() { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(targetHost, httpDelete); Log.v("Delete to GAE", Utilities.convertStreamToString(response.getEntity().getContent())); } catch (Exception ex) { ex.printStackTrace();//from w w w .j ava 2 s . c om } } }; Thread thread = new Thread(null, sendRunnable, "deleteToGAE"); thread.start(); }
From source file:Main.java
public static Dialog backgroundProcess(Context context, final Runnable run, final boolean showDialog, String loadingComment) {//w ww.j a va 2s.c om final ProgressDialog progressdialog = creativeProgressBar(context, loadingComment); if (showDialog) progressdialog.show(); Runnable wrapper = new Runnable() { public void run() { run.run(); if (showDialog) progressdialog.dismiss(); } }; Thread thread = new Thread(wrapper); thread.setDaemon(true); thread.start(); return progressdialog; }
From source file:edu.umn.cs.spatialHadoop.util.MemoryReporter.java
public static Thread startReporting() { Thread thread = new Thread(new MemoryReporter(), "MemReporter"); thread.setDaemon(true);/*w ww . j a v a2s. c o m*/ thread.start(); return thread; }
From source file:TimeoutController.java
/** * Executes <code>task</code>. Waits for <code>timeout</code> * milliseconds for the task to end and returns. If the task does not return * in time, the thread is interrupted and an Exception is thrown. * The caller should override the Thread.interrupt() method to something that * quickly makes the thread die or use Thread.isInterrupted(). * @param task The thread to execute//from w ww . j a v a 2 s. com * @param timeout The timeout in milliseconds. 0 means to wait forever. * @throws TimeoutException if the timeout passes and the thread does not return. */ public static void execute(Thread task, long timeout) throws TimeoutException { task.start(); try { task.join(timeout); } catch (InterruptedException e) { /* if somebody interrupts us he knows what he is doing */ } if (task.isAlive()) { task.interrupt(); throw new TimeoutException(); } }
From source file:com.apporiented.hermesftp.server.impl.AbstractClientServerTestCase.java
private static void startServer(FtpServer svr) { Thread svrThread = new Thread(svr); svrThread.start(); while (svr.getStatus() != SERVER_STATUS_READY) { try {//from w w w. j a v a 2s . co m Thread.sleep(SERVER_DELAY); } catch (InterruptedException e) { log.error(e); break; } } }
From source file:InterruptibleSyncBlock.java
private static Thread launch(final InterruptibleSyncBlock sb, String name) { Runnable r = new Runnable() { public void run() { print("in run()"); try { sb.doStuff();//from w w w . java2 s . c o m } catch (InterruptedException x) { print("InterruptedException thrown " + "from doStuff()"); } } }; Thread t = new Thread(r, name); t.start(); return t; }
From source file:com.clustercontrol.winsyslog.UdpSender.java
/** * ??/*from w ww . jav a 2s . c o m*/ * @param sendBuff ? */ public static void send(byte[] sendBuff) { if (toAddresses == null) { log.warn("UdpSender is not Initialised."); return; } else if (toAddresses.length == 0) { log.warn("send target is none."); return; } SenderTask sender = new SenderTask(sendBuff); Thread thread = new Thread(sender); thread.start(); }
From source file:TransitionDetectorMain.java
private static Thread startTrueWaiter(final TransitionDetector td, String name) { Runnable r = new Runnable() { public void run() { try { while (true) { print("about to wait for false-to-" + "true transition, td=" + td); td.waitForFalseToTrueTransition(); print("just noticed for false-to-" + "true transition, td=" + td); }/*from www . j a v a 2 s .c om*/ } catch (InterruptedException ix) { return; } } }; Thread t = new Thread(r, name); t.start(); return t; }