List of usage examples for java.lang Thread start
public synchronized void start()
From source file:net.rpproject.dl.download.java
public static void downloadFile(String fileurl) { Runnable runner;/*from w w w . ja va 2 s. c om*/ runner = () -> { try { fileDownloader(fileurl); } catch (IOException ex) { Logger.getLogger(window.class.getName()).log(Level.SEVERE, null, ex); } }; Thread t = new Thread(runner, "RRP Download Thread"); t.start(); }
From source file:com.sshtools.common.util.ShutdownHooks.java
public static synchronized void exit(final boolean exit) { Iterator ifiles = files.iterator(); while (ifiles.hasNext()) { String file = (String) ifiles.next(); File f = new File(file); if (f != null & f.exists()) { f.delete();/*from www. j a va 2s. c o m*/ } } Iterator icodes = codes.iterator(); Notif n = new Notif(codes.size()); while (icodes.hasNext()) { Runnable code = (Runnable) icodes.next(); try { Thread t = new Helper(code, n); t.start(); if (!exit) t.join(); } catch (IllegalThreadStateException e) { log.error("Exception", e); } catch (InterruptedException e) { log.error("Exception", e); } } files = new LinkedList(); codes = new LinkedList(); if (exit) n.start(); }
From source file:Main.java
public static Runnable excAsync(final Runnable runnable, boolean isDeamon) { Thread thread = new Thread() { @Override/*from w w w . j a v a 2s. c o m*/ public void run() { runnable.run(); } }; thread.setDaemon(isDeamon); thread.start(); return runnable; }
From source file:com.espertech.esper.regression.nwtable.TestTableMTGroupedWContextIntoTableWriteAsSharedTable.java
protected static void runAndAssert(EPServiceProvider epService, String eplDeclare, String eplAssert, int numThreads, int numLoops, int numGroups) throws Exception { epService.getEPAdministrator().getDeploymentAdmin().parseDeploy(eplDeclare); // setup readers Thread[] writeThreads = new Thread[numThreads]; WriteRunnable[] writeRunnables = new WriteRunnable[numThreads]; for (int i = 0; i < writeThreads.length; i++) { writeRunnables[i] = new WriteRunnable(epService, numLoops, numGroups); writeThreads[i] = new Thread(writeRunnables[i]); }//from ww w . j av a 2s. co m // start for (Thread writeThread : writeThreads) { writeThread.start(); } // join log.info("Waiting for completion"); for (Thread writeThread : writeThreads) { writeThread.join(); } // assert for (WriteRunnable writeRunnable : writeRunnables) { assertNull(writeRunnable.getException()); } // each group should total up to "numLoops*numThreads" SupportUpdateListener listener = new SupportUpdateListener(); epService.getEPAdministrator().createEPL(eplAssert).addListener(listener); Integer expected = numLoops * numThreads; for (int i = 0; i < numGroups; i++) { epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "G" + i)); assertEquals(expected, listener.assertOneGetNewAndReset().get("c0")); } }
From source file:Main.java
private static void runTest() throws InterruptedException { Collection<String> syncList = Collections.synchronizedList(new ArrayList<String>(1)); List<String> list = Arrays.asList("A", "B", "C", "D"); List<Thread> threads = new ArrayList<Thread>(); for (final String s : list) { Thread thread = new Thread(new Runnable() { @Override/*from www . ja v a2 s .c o m*/ public void run() { syncList.add(s); } }); threads.add(thread); thread.start(); } for (Thread thread : threads) { thread.join(); } System.out.println(syncList); }
From source file:io.seldon.api.service.async.JdoAsyncActionFactory.java
private static AsyncActionQueue create(String client, int qtimeoutSecs, int batchSize, int qSize, int dbRetries, boolean runUserItemUpdates, boolean runUpdateIdsActionTable, boolean insertActions) { JdoAsyncActionQueue q = new JdoAsyncActionQueue(client, qtimeoutSecs, batchSize, qSize, dbRetries, runUserItemUpdates, runUpdateIdsActionTable, insertActions); Thread t = new Thread(q); t.start(); return q;//w w w . j a v a 2 s .c o m }
From source file:com.hurence.logisland.hadoop.SecurityUtil.java
/** * Start a thread that periodically attempts to renew the current Kerberos user's ticket. * * Callers of this method should store the reference to the KerberosTicketRenewer and call stop() to stop the thread. * * @param id/*from www . j a va2 s . c o m*/ * The unique identifier to use for the thread, can be the class name that started the thread * (i.e. PutHDFS, etc) * @param ugi * The current Kerberos user. * @param renewalPeriod * The amount of time between attempting renewals. * @param logger * The logger to use with in the renewer * * @return the KerberosTicketRenewer Runnable */ public static KerberosTicketRenewer startTicketRenewalThread(final String id, final UserGroupInformation ugi, final long renewalPeriod, final ComponentLog logger) { final KerberosTicketRenewer renewer = new KerberosTicketRenewer(ugi, renewalPeriod, logger); final Thread t = new Thread(renewer); t.setName("Kerberos Ticket Renewal [" + id + "]"); t.start(); return renewer; }
From source file:Main.java
static void performSorting(MyModel myArrayClass) { Thread thread = new Thread(() -> { myArrayClass.QuickSort(0, myArrayClass.arraySize - 1); System.out.println("Done"); });//from w ww . ja v a 2s .c o m thread.start(); }
From source file:net.dryuf.concurrent.benchmark.BenchmarkSupport.java
public static void threadedRunFutures(RunnableFuture<Integer>[] array) { Thread t = new Thread(() -> { for (RunnableFuture<Integer> v : array) { v.run();//from ww w . j a v a 2 s . c om } }); t.start(); try { t.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Runs a thread asynchronously.//from ww w.ja v a 2s . c om * * @param thread The thread (Runnable) to run. * @param name The name of the thread. */ public static void startThread(Runnable thread, String name) { //Adds the desired thread to the list and starts it Thread newThread; if (name != null) newThread = new Thread(thread, name); else newThread = new Thread(thread); threads.add(newThread); newThread.start(); }