Example usage for java.lang Thread interrupted

List of usage examples for java.lang Thread interrupted

Introduction

In this page you can find the example usage for java.lang Thread interrupted.

Prototype

public static boolean interrupted() 

Source Link

Document

Tests whether the current thread has been interrupted.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println("#1:" + Thread.interrupted());

    // Now interrupt the main thread
    Thread.currentThread().interrupt();

    // Check if it has been interrupted
    System.out.println("#2:" + Thread.interrupted());

    // Check again if it has been interrupted
    System.out.println("#3:" + Thread.interrupted());
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("#1:" + Thread.interrupted());

    Thread mainThread = Thread.currentThread();
    mainThread.interrupt();/*from  w  w w .  java  2s .  co m*/

    System.out.println("#2:" + mainThread.isInterrupted());

    System.out.println("#3:" + mainThread.isInterrupted());

    System.out.println("#4:" + Thread.interrupted());

    System.out.println("#5:" + mainThread.isInterrupted());
}

From source file:InterruptReset.java

public static void main(String[] args) {
    System.out.println("Thread.interrupted()=" + Thread.interrupted());
    Thread.currentThread().interrupt();
    System.out.println("Thread.interrupted()=" + Thread.interrupted());
    System.out.println("Thread.interrupted()=" + Thread.interrupted());
}

From source file:ThreadDemo.java

public static void main(String args[]) {

    Thread t = new Thread(new ThreadDemo());
    System.out.println("Executing " + t.getName());
    t.start();/*from   w w w.ja v  a2s  .  c  om*/

    if (!t.interrupted()) {
        t.interrupt();
    }
    // block until other threads finish
    try {
        t.join();
    } catch (InterruptedException e) {
    }
}

From source file:ThreadDemo.java

public static void main(String args[]) {
    Thread t = new Thread(new ThreadDemo());
    System.out.println("Executing " + t.getName());
    // this will call run() fucntion
    t.start();/*from   ww w  . jav  a2  s . c  om*/

    // interrupt the threads
    if (!t.interrupted()) {
        t.interrupt();
    }
    // block until other threads finish
    try {
        t.join();
    } catch (InterruptedException e) {
    }
}

From source file:eu.stratosphere.sopremo.server.SopremoServer.java

/**
 * Entry point for the program//from w w w  . j a  v a2 s . co m
 * 
 * @param args
 *        arguments from the command line
 */
@SuppressWarnings("static-access")
public static void main(final String[] args) {

    final Option configDirOpt = OptionBuilder.withArgName("config directory").hasArg()
            .withDescription("Specify configuration directory.").create("configDir");

    final Options options = new Options();
    options.addOption(configDirOpt);

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, args);
        final String configDir = line.getOptionValue(configDirOpt.getOpt(), null);
        GlobalConfiguration.loadConfiguration(configDir);
    } catch (ParseException e) {
        LOG.error("CLI Parsing failed. Reason: " + e.getMessage());
        System.exit(1);
    }

    // start server
    SopremoServer sopremoServer = new SopremoServer();
    try {
        sopremoServer.start();
    } catch (IOException e) {
        LOG.error("Cannot start Sopremo server: " + StringUtils.stringifyException(e));
        sopremoServer.close();
        return;
    }

    // and wait for any shutdown signal
    while (!Thread.interrupted()) {
        // Sleep
        try {
            Thread.sleep(SLEEPINTERVAL);
        } catch (InterruptedException e) {
            break;
        }
        // Do nothing here
    }
}

From source file:Main.java

public static boolean isInterrupted() {
    final boolean isInterrupted = Thread.interrupted();
    if (isInterrupted) {
    }/*from  w w w . j av a2 s.com*/
    return isInterrupted;
}

From source file:Main.java

public static void checkInterrupted() throws InterruptedException {
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }//from  w  w  w . j  ava 2 s  .c om
}

From source file:Main.java

public static void run() {
    int counter = 0;
    while (!Thread.interrupted()) {
        counter++;/* www  . j  a v  a 2 s  .c  om*/
    }
    System.out.println("Counter:" + counter);
}

From source file:Main.java

/**
 * Checks if the current thread /*from   ww  w  .  j a  v  a 2 s  . com*/
 * 
 * @throws InterruptedException     if the current thread was interrupted
 */
public static void checkIfInterrupted() throws InterruptedException {
    // make this thread interruptible, if called from SwingWorker
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }
}