List of usage examples for java.lang Thread start
public synchronized void start()
From source file:net.pms.util.ProcessUtil.java
public static void destroy(final Process p) { if (p != null) { final Integer pid = getProcessID(p); if (pid != null) { // Unix only LOGGER.trace("Killing the Unix process: " + pid); Runnable r = new Runnable() { @Override//w w w . j ava 2s . c om public void run() { try { Thread.sleep(TERM_TIMEOUT); } catch (InterruptedException e) { } try { p.exitValue(); } catch (IllegalThreadStateException itse) { // still running: nuke it // kill -14 (ALRM) works (for MEncoder) and is less dangerous than kill -9 // so try that first if (!kill(pid, 14)) { try { // This is a last resort, so let's not be too eager Thread.sleep(ALRM_TIMEOUT); } catch (InterruptedException ie) { } kill(pid, 9); } } } }; Thread failsafe = new Thread(r, "Process Destroyer"); failsafe.start(); } p.destroy(); } }
From source file:co.paralleluniverse.fibers.retrofit.FiberRestAdapterBuilderTest.java
@BeforeClass public static void setUpClass() throws InterruptedException, IOException { Thread t = new Thread(new Runnable() { @Override/* w ww. j a v a 2s . com*/ public void run() { try { new HelloWorldApplication().run(new String[] { "server" }); } catch (Exception ex) { } } }); t.setDaemon(true); t.start(); waitUrlAvailable("http://localhost:8080"); }
From source file:au.org.ala.layers.util.BatchConsumer.java
synchronized public static void start(LayerIntersectDAO layerIntersectDao, String batchDir) { if (threads.size() == 0) { waitingBatchDirs = new LinkedBlockingQueue<String>(); int size = Integer.parseInt( (new UserProperties()).getProperties().getProperty("batch_sampling_parallel_requests", "1")); for (int i = 0; i < size; i++) { Thread t = new BatchConsumerThread(waitingBatchDirs, layerIntersectDao, batchDir); t.start(); threads.add(t);//from w ww . j av a2 s .c om } //get jobs that may have been interrupted but a shutdown File f = new File(batchDir); File[] files = f.listFiles(); java.util.Arrays.sort(files); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory() && !(new File(files[i].getPath() + File.separator + "error.txt")).exists() && !(new File(files[i].getPath() + File.separator + "finished.txt")).exists()) { System.out.println("found incomplete batch_sampling: " + files[i].getPath()); try { addBatch(files[i].getPath() + File.separator); } catch (InterruptedException e) { } } } } }
From source file:au.org.ala.spatial.util.BatchConsumer.java
synchronized public static void start(LayerIntersectDAO layerIntersectDao, String batchDir) { if (threads.size() == 0) { waitingBatchDirs = new LinkedBlockingQueue<String>(); int size = Integer.parseInt( (new UserProperties()).getProperties().getProperty("batch_sampling_parallel_requests", "1")); for (int i = 0; i < size; i++) { Thread t = new BatchConsumerThread(waitingBatchDirs, layerIntersectDao, batchDir); t.start(); threads.add(t);//from www . java 2 s .c o m } //get jobs that may have been interrupted but a shutdown File f = new File(batchDir); File[] files = f.listFiles(); Arrays.sort(files); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory() && !(new File(files[i].getPath() + File.separator + "error.txt")).exists() && !(new File(files[i].getPath() + File.separator + "finished.txt")).exists()) { System.out.println("found incomplete batch_sampling: " + files[i].getPath()); try { addBatch(files[i].getPath() + File.separator); } catch (InterruptedException e) { } } } } }
From source file:Test.java
private static void startUpdateThread(int i, final ConcurrentMap<Integer, String> concurrentMap) { Thread thread = new Thread(new Runnable() { public void run() { while (!Thread.interrupted()) { Random random = new Random(); int randomInt = random.nextInt(20); concurrentMap.put(randomInt, UUID.randomUUID().toString()); }//www . ja v a 2 s.co m } }); thread.setName("Update Thread " + i); updateThreads.add(thread); thread.start(); }
From source file:org.opennms.mock.snmp.MockSnmpAgent.java
public static MockSnmpAgent createAgentAndRun(Resource moFile, String bindAddress) throws InterruptedException { try {//from w w w .j a va 2 s . c o m if (moFile.getInputStream() == null) { throw new IllegalArgumentException( "could not get InputStream mock object resource; does it exist? Resource: " + moFile); } } catch (IOException e) { throw new RuntimeException("Got IOException while checking for existence of mock object file: " + e, e); } MockSnmpAgent agent = new MockSnmpAgent(new File("/dev/null"), new File("/dev/null"), moFile, bindAddress); Thread thread = new Thread(agent); thread.start(); try { while (!agent.isRunning() && thread.isAlive()) { Thread.sleep(10); } } catch (InterruptedException e) { agent.shutDownAndWait(); throw e; } if (!thread.isAlive()) { agent.m_running = false; agent.m_stopped = true; throw new IllegalStateException("agent failed to start--check logs"); } return agent; }
From source file:com.pwned.utils.VersionCheck.java
private static void validateVersion() { a = new AlertDialog.Builder(context).create(); Thread runOnce = new Thread() { @Override/*w w w . j a va 2 s . c o m*/ public void run() { Logger.log("start version check", "start check"); try { _versionCheck(); } catch (IOException e) { } } }; runOnce.start(); returnRes = new Thread() { @Override public void run() { if (versionName < currentVersionName) showUpdate(); } }; }
From source file:mitm.common.net.HTTPMethodExecutorTest.java
private static void startServer() { server = new SimpleSocketServer(SERVER_PORT); Thread serverThread = new Thread(server); serverThread.setDaemon(true);/*from www. ja v a 2 s.co m*/ serverThread.start(); while (!server.isRunning()) { try { Thread.sleep(100); } catch (InterruptedException e) { // ignore } } }
From source file:com.aan.girsang.client.launcher.ClientLauncher.java
public static void jam(JLabel lbl) { Thread t = new Thread(() -> { while (true) { lbl.setText(new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss").format(new Date())); try { Thread.sleep(1000); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); }/*from ww w .j a va 2s . c o m*/ } }); t.start(); }
From source file:com.google.appengine.tck.byteman.ConcurrentTxTestBase.java
protected static Thread execute(final CloseableHttpClient client, final HttpUriRequest request, final Holder holder) { Thread thread = new Thread(new Runnable() { public void run() { try { try (CloseableHttpResponse response = client.execute(request)) { holder.out = EntityUtils.toString(response.getEntity()); }//from w ww . j a va2s .c om } catch (IOException ignore) { } } }); thread.start(); return thread; }