List of usage examples for java.lang InterruptedException printStackTrace
public void printStackTrace()
From source file:Main.java
public static long sleep(long time) { try {// w w w. jav a2s .c o m Thread.currentThread(); Thread.sleep(time); } catch (InterruptedException e) { System.out.println("[ThreadUtils]-thread sleep error!"); e.printStackTrace(); } return time; }
From source file:com.freebox.engeneering.application.system.ApplicationContextLocator.java
public static ApplicationContext getApplicationContext() { try {//ww w . java 2 s . c o m synchronized (monitor) { while (ApplicationContextLocator.applicationContext == null) { monitor.wait(); } } } catch (InterruptedException e) { e.printStackTrace(); } return ApplicationContextLocator.applicationContext; }
From source file:com.freebox.engeneering.application.system.ApplicationContextLocator.java
public static Collection<URL> getWebFlowConfiguration() { try {//w ww . j a v a 2 s.c o m synchronized (monitor) { while (ApplicationContextLocator.webFlowConfiguration == null) { monitor.wait(); } } } catch (InterruptedException e) { e.printStackTrace(); } return ApplicationContextLocator.webFlowConfiguration; }
From source file:org.opencredo.esper.samples.noodlebar.main.AsyncNoodleOrderGenerator.java
private static void sendSomeOrders() { NoodleOrder[] orders = new NoodleOrder[NUMBER_OF_ORDERS]; // Create and send events for (int x = 0; x < NUMBER_OF_ORDERS; x++) { orders[x] = new NoodleOrder(); noodleBar.placeOrder(orders[x]); // Sleep a little bit between orders try {/* ww w . j a v a2s . com*/ Thread.sleep(5l); } catch (InterruptedException e) { e.printStackTrace(); } } boolean processing = true; while (processing) { processing = false; for (NoodleOrder order : orders) { if (order.getStatus() == OrderStatus.COMPLETE) { System.out.println("Order Completed!"); } else { processing = true; } } try { Thread.sleep(20l); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:Main.java
public static void slowDebug(String TAG, String text, int sleep) { for (String s : text.split("\n")) { Log.d(TAG, s);/* ww w . j a v a 2s . c o m*/ try { Thread.sleep(sleep); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:example.rhino.DynamicScopesWithHandlebars.java
private static void runScripts(Context cx, Script script, ExecutorService executor) { ScriptableObject sharedScope = cx.initStandardObjects(null, true); script.exec(cx, sharedScope);/*from ww w . j av a 2s .co m*/ Runnable[] run = new Runnable[NUM_THREAD]; for (int i = 0; i < NUM_THREAD; i++) { String source2 = "Handlebars.precompile(template)"; run[i] = new PerThread(sharedScope, source2, i); } for (int i = 0; i < NUM_THREAD; i++) { executor.execute(run[i]); } executor.shutdown(); try { executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:Main.java
public static String sudoForResult(String... strings) { String res = ""; DataOutputStream outputStream = null; InputStream response = null;// w w w. ja va 2 s . c o m try { Process su = Runtime.getRuntime().exec("su"); outputStream = new DataOutputStream(su.getOutputStream()); response = su.getInputStream(); for (String s : strings) { outputStream.writeBytes(s + "\n"); outputStream.flush(); } outputStream.writeBytes("exit\n"); outputStream.flush(); try { su.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } res = readFully(response); } catch (IOException e) { e.printStackTrace(); } finally { closeSilently(outputStream, response); } return res; }
From source file:Main.java
/** * Runs each runnable in a new thread. This method blocks until all runnables are complete. * Before any runnables are run, we also wait until the allocated thread has ran at least once. * This is done to increase the randomness in the order of thread execution. *///from ww w.j a v a2s . com public static void startMultipleThreadsAndWaitUntilComplete(final List<Runnable> runnables) throws Exception { final Semaphore competingThreadsStarted = new Semaphore(0); // Number of threads for runnables started. final Semaphore competingThreadsToRelease = new Semaphore(0); // Acquired by runnable threads. Will be released // once all runnables have been run once. final Semaphore competingThreadsCompleted = new Semaphore(0); // Number of runnable threads completed. for (int i = 0; i < runnables.size(); i++) { final int runnableIndex = i; new Thread(new Runnable() { @Override public void run() { try { // Notify semaphore that this thread has been started. competingThreadsStarted.release(1); // Once all threads have notified the competingThreadsStarted semaphore, // competingThreadsToRelease will be released and we will continue. competingThreadsToRelease.acquire(1); // Increases randomness of thread execution order. Thread.sleep(1); runnables.get(runnableIndex).run(); // thread has completed running provided runnable. competingThreadsCompleted.release(1); } catch (final InterruptedException e) { e.printStackTrace(); } } }).start(); } // Only proceed once all threads have at least started running once. competingThreadsStarted.acquire(runnables.size()); // Release all threads. competingThreadsToRelease.release(runnables.size()); // Wait until all threads have completed before returning. competingThreadsCompleted.acquire(runnables.size()); }
From source file:Main.java
/** * Causes <code>runnable</code> to have its <code>run</code> method called * in the dispatch thread of {@link Toolkit#getSystemEventQueue the system * EventQueue} if this method is not being called from it. This will happen * after all pending events are processed. The call blocks until this has * happened. This method will throw an Error if called from the event * dispatcher thread./*from w ww. j a va 2 s.c om*/ * * @param runnable * the <code>Runnable</code> whose <code>run</code> method should * be executed synchronously on the <code>EventQueue</code> */ public static void invokeOnEdtAndWait(Runnable runnable) { boolean isEdt = EventQueue.isDispatchThread(); if (!isEdt) { try { EventQueue.invokeAndWait(runnable); } catch (InterruptedException e) { System.err.println("EDT task interrupted"); e.printStackTrace(); } catch (InvocationTargetException e) { System.err.println("EDT task invocation exception"); e.printStackTrace(); } } else { runnable.run(); } }
From source file:Main.java
public static void smoothToTransparentFromColor(final View view, final int color) { Date firstDate = new Date(); final long firstTime = firstDate.getTime(); executeAsyncTask(new AsyncTask<Void, Integer, Void>() { int n = 1, t = 4000; boolean increaseN; @Override/* ww w . ja v a 2 s . c o m*/ protected Void doInBackground(Void... params) { while (!isCancelled()) { Date currentDate = new Date(); long diffTime = currentDate.getTime() - firstTime; double y = getCosY(diffTime); int alpha = (int) (y * Color.alpha(color)); int resultColor = setAlphaComponent(color, alpha); if (alpha < 0.038 * 255) { publishProgress(0); this.cancel(true); return null; } publishProgress(resultColor, alpha); try { Thread.sleep(38); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); view.setBackgroundColor(values[0]); } }); }