List of usage examples for java.lang Thread start
public synchronized void start()
From source file:gov.vha.isaac.ochre.api.LookupService.java
/** * start all core isaac services in a background thread, returning immediately. * @param callWhenStartComplete (optional) - if provided, a call back will be provided * notifying of successfully start of ISAAC, or providing the Exception, if the startup sequence failed. *///from w w w . j a va 2 s . com public static void startupIsaac(BiConsumer<Boolean, Exception> callWhenStartComplete) { log.info("Background starting ISAAC services"); Thread backgroundLoad = new Thread(() -> { try { startupIsaac(); log.info("Background start complete - runlevel now " + getService(RunLevelController.class).getCurrentRunLevel()); if (callWhenStartComplete != null) { callWhenStartComplete.accept(isIsaacStarted(), null); } } catch (Exception e) { log.warn("Background start failed - runlevel now " + getService(RunLevelController.class).getCurrentRunLevel(), e); if (callWhenStartComplete != null) { callWhenStartComplete.accept(false, e); } } }, "Datastore init thread"); backgroundLoad.start(); }
From source file:com.amazonaws.utilities.Util.java
public static void refreshToken() { Thread loginThread = new Thread(new Runnable() { @Override//from ww w.j av a 2 s . c o m public void run() { JSONObject json = new JSONObject(); try { json.put("email", Prefs.getString("email", "")); json.put("password", getKey()); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String responseLogin = NetworkClass.HTTPPost(Global.MOBILE_CUSTOMER_LOGIN_URL, json); Log.d("Utilities", "URL: " + Global.MOBILE_CUSTOMER_LOGIN_URL + ", RESPONSE : " + responseLogin); processLoginResponse(responseLogin); } }); loginThread.start(); }
From source file:com.tascape.qa.th.Utils.java
public static void waitForOutputLine(final Process process, String lineExpected, final long timeout) throws IOException { Thread t = new Thread() { @Override/* w ww. ja v a 2 s .c om*/ public void run() { try { Thread.sleep(timeout); } catch (InterruptedException ex) { LOG.warn(ex.getMessage()); } finally { if (process != null) { process.destroy(); } } } }; t.setName(Thread.currentThread().getName() + "-" + t.hashCode()); t.setDaemon(true); t.start(); try (BufferedReader stdIn = new BufferedReader(new InputStreamReader(process.getInputStream()))) { for (String line = stdIn.readLine(); line != null;) { if (line.contains(lineExpected)) { break; } line = stdIn.readLine(); } } t.interrupt(); }
From source file:MainClass.java
public MarketDataModel(int initialDelay) { Thread runner = new Thread(this); runner.start(); }
From source file:A.java
Deadlock() { Thread.currentThread().setName("MainThread"); Thread t = new Thread(this, "RacingThread"); t.start(); a.foo(b); // get lock on a in this thread. System.out.println("Back in main thread"); }
From source file:Test.java
public Test() { Runnable runner = new MyRunnable("First"); Thread t = new Thread(runner); t.setPriority(Thread.MIN_PRIORITY); t.start(); runner = new MyRunnable("Second"); t = new Thread(runner); t.setPriority(Thread.MAX_PRIORITY); t.start();//from ww w .j a v a 2s . c om }
From source file:ThreadTask.java
public ThreadPool(int size) { for (int i = 0; i < size; i++) { Thread thread = new ThreadTask(this); thread.start(); }/*from w w w . j a v a 2s. co m*/ }
From source file:com.hkd.socketclient.IOUtil.java
public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput, final InputStream localInput, final OutputStream localOutput) { Thread reader, writer; reader = new Thread() { @Override//from w w w.j av a2s . c o m public void run() { int ch; try { while (!interrupted() && (ch = localInput.read()) != -1) { remoteOutput.write(ch); remoteOutput.flush(); } } catch (IOException e) { //e.printStackTrace(); } } }; writer = new Thread() { @Override public void run() { try { Util.copyStream(remoteInput, localOutput); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } }; writer.setPriority(Thread.currentThread().getPriority() + 1); writer.start(); reader.setDaemon(true); reader.start(); try { writer.join(); reader.interrupt(); } catch (InterruptedException e) { } }
From source file:Main.java
private void shakeButton() { final Point point = button.getLocation(); final int delay = 75; Runnable r = new Runnable() { @Override//from w ww . j a v a2 s.c o m public void run() { for (int i = 0; i < 30; i++) { try { moveButton(new Point(point.x + 5, point.y)); Thread.sleep(delay); moveButton(point); Thread.sleep(delay); moveButton(new Point(point.x - 5, point.y)); Thread.sleep(delay); moveButton(point); Thread.sleep(delay); } catch (InterruptedException ex) { ex.printStackTrace(); } } } }; Thread t = new Thread(r); t.start(); }
From source file:Main.java
private void shakeButton() { final Point point = button.getLocation(); final Insets margin = button.getMargin(); final int delay = 75; Runnable r = new Runnable() { @Override/*from w w w . ja v a2 s. com*/ public void run() { for (int i = 0; i < 30; i++) { try { setButtonMargin(new Insets(margin.top, margin.left + 3, margin.bottom, margin.right - 2)); Thread.sleep(delay); setButtonMargin(margin); Thread.sleep(delay); setButtonMargin(new Insets(margin.top, margin.left - 2, margin.bottom, margin.right + 3)); Thread.sleep(delay); setButtonMargin(margin); Thread.sleep(delay); } catch (InterruptedException ex) { ex.printStackTrace(); } } } }; Thread t = new Thread(r); t.start(); }