Example usage for java.lang InterruptedException printStackTrace

List of usage examples for java.lang InterruptedException printStackTrace

Introduction

In this page you can find the example usage for java.lang InterruptedException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

/**
 * Waits for all threads to complete computation.
 * /*from   ww  w . j a va 2s . c  o m*/
 * @param futures
 */
public static void waitForCompletion(Future<?>[] futures) {
    int size = futures.length;
    try {
        for (int j = 0; j < size; j++) {
            futures[j].get();
        }
    } catch (ExecutionException ex) {
        ex.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:info.smartkit.hairy_batman.demo.MoniterWechatBrowser.java

/**
 * ?URLhtml?//from  www .j  a va2  s  .co  m
 */
@SuppressWarnings("deprecation")
public static String getHttpClientHtml(String url, String code, String userAgent) {
    String html = null;
    @SuppressWarnings("deprecation")
    DefaultHttpClient httpClient = new DefaultHttpClient();// httpClient
    HttpGet httpget = new HttpGet(url);// get?URL
    // Pause for 4 seconds
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
        System.out.println(e1.toString());
    }
    //
    httpget.setHeader("User-Agent", userAgent);
    try {
        // responce
        HttpResponse responce = httpClient.execute(httpget);
        // ?
        int returnCode = responce.getStatusLine().getStatusCode();
        // 200? ?
        if (returnCode == HttpStatus.SC_OK) {
            // 
            HttpEntity entity = responce.getEntity();
            if (entity != null) {
                html = new String(EntityUtils.toString(entity));// html??
            }
        }
    } catch (Exception e) {
        System.out.println("");
        e.printStackTrace();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
    return html;
}

From source file:Main.java

public static void sleepThread(long time) {
    try {//ww  w  .j  av  a2s  .  c  o  m
        Thread.sleep(time);
    } catch (InterruptedException ex) {
        System.out.println("Error sleeping thread");
        ex.printStackTrace();
    }
}

From source file:Main.java

public static boolean isRooted() {
    Process p;// w w w .  j  a v  a 2s .  c  o m
    try {
        p = new ProcessBuilder("su").start();
        BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
        BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));

        stdin.write("whoami");
        stdin.newLine();
        stdin.write("exit");
        stdin.newLine();
        stdin.close();
        try {
            p.waitFor();
            if (!stdout.ready())
                return false;
            String user = stdout.readLine(); //We only expect one line of output
            stdout.close();
            if (user == "root") {
                return true;
            } else {
                return false;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:name.milesparker.gerrit.analysis.CollectGit.java

protected static void formatFiles(String rootDir) {
    System.out.println("Converting: " + rootDir);
    SimpleFileConverter converter = new SimpleFileConverter(rootDir, "txt", new String[] { "git" },
            REPLACEMENTS);/* www. j  a  va 2  s  . c  o m*/
    converter.setLogToConsole(false);
    converter.setUser(true);
    converter.schedule();
    while (converter.getResult() == null) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.err.println(converter.getResult().getMessage());
}

From source file:Main.java

public static void sleep(long mil) {
    /*/*ww  w .ja  va  2s  .  c  o  m*/
                
    double cur = System.currentTimeMillis();
    while (System.currentTimeMillis() - cur < mil)
    {
                   
    }
     */
    try {
        Thread.sleep(mil);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:AsyncExecDisplay.java

public static Thread getTask2(Button button) {
    final Button theButton = button;
    return new Thread() {
        public void run() {

            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }/*from  w  ww . j  av a  2s. com*/

            display.asyncExec(new Runnable() {
                public void run() {
                    theButton.setText("done");
                }
            });
        }
    };
}

From source file:Main.java

public static void runOnEventDispatchThread(Runnable runnable) {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();/* w ww  .  jav  a 2s .c  o m*/
    } else
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InvocationTargetException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
}

From source file:Main.java

/**
 * Sleep thread for seconds.//from   www .  j  ava 2 s. c o  m
 *
 * @param milisecond
 */
public static void sleepForInSecs(Integer milisecond) {
    try {
        // do what you want to do before sleeping
        Thread.currentThread().sleep(milisecond);// sleep for 1000 ms
        // do what you want to do after sleeptig
    } catch (InterruptedException ie) {
        // If this thread was intrrupted by nother thread
        ie.printStackTrace();
    }
}

From source file:Main.java

public static void wait_sound(MediaPlayer _sound) {
    if (_sound != null) {
        while (_sound.isPlaying()) {
            try {
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }/*from w  w w .j av  a  2  s  .  c  om*/
        }
    }
}