Example usage for java.lang Thread interrupt

List of usage examples for java.lang Thread interrupt

Introduction

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

Prototype

public void interrupt() 

Source Link

Document

Interrupts this thread.

Usage

From source file:edu.umn.msi.tropix.jobs.activities.factories.PollJobActivityFactoryImpl.java

public void shutdown() {
    synchronized (threads) {
        shutdown.set(true);/*from   w ww  .j  a va2 s  .c om*/
        for (Thread thread : threads.values()) {
            thread.interrupt();
        }
    }
}

From source file:org.apache.http.impl.conn.tsccm.RefQueueWorker.java

/**
 * Shuts down this worker.//from w w w . j a va  2 s . c om
 * It can be re-started afterwards by another call to {@link #run run()}.
 */
public void shutdown() {
    Thread wt = this.workerThread;
    if (wt != null) {
        this.workerThread = null; // indicate shutdown
        wt.interrupt();
    }
}

From source file:org.apache.hadoop.hbase.ipc.SimpleRpcScheduler.java

@Override
public void stop() {
    running = false;
    for (Thread handler : handlers) {
        handler.interrupt();
    }
}

From source file:org.feistymeow.process.ethread.java

/**
 * Signals the thread to stop executing, but does not wait for it.
 *//* w  w  w.ja va  2  s  .co m*/
void cancel() {
    synchronized (c_lock) {
        c_stopThread = true;
        Thread goAway = c_RealThread;
        c_RealThread = null;
        if (null != goAway) {
            goAway.interrupt();
        }
    }
}

From source file:com.thoughtworks.go.config.BackgroundMailSender.java

private ValidationBean execute(Runnable action) {
    Thread thread = new Thread(action);
    thread.start();//from w w w.  ja  v a  2 s.  com
    try {
        thread.join(timeout);
        if (thread.isAlive()) {
            thread.interrupt();
            return ValidationBean.notValid(ERROR_MESSAGE);
        }
        return validation;
    } catch (InterruptedException e) {
        LOGGER.error("Timed out when sending an email. Please check email configuration.");
        return ValidationBean.notValid(ERROR_MESSAGE);
    }
}

From source file:com.atlassian.theplugin.idea.config.serverconfig.defaultCredentials.TestDefaultCredentialsDialog.java

public void doCancelAction() {
    for (Thread thread : threads) {
        thread.interrupt();
    }/*from   ww w  .  j a  va2 s  .c  o  m*/
    super.doCancelAction();
}

From source file:com.sonatype.nexus.perftest.ClientSwarm.java

public void stop() throws InterruptedException {
    for (Thread thread : threads) {
        for (int i = 0; i < 3 && thread.isAlive(); i++) {
            thread.interrupt();
            thread.join(1000L);/*w ww . jav a 2 s . c  o m*/
        }
        if (thread.isAlive()) {
            StringBuilder sb = new StringBuilder(
                    String.format("Thread %s ignored interrupt flag\n", thread.getName()));
            for (StackTraceElement f : thread.getStackTrace()) {
                sb.append("\t").append(f.toString()).append("\n");
            }
            System.err.println(sb.toString());
        }
    }
}

From source file:com.alibaba.napoli.gecko.service.impl.ReconnectManager.java

public synchronized void stop() {
    if (!this.started) {
        return;//ww  w  .  j  ava 2 s .c om
    }
    this.started = false;
    for (final Thread thread : this.healConnectionThreads) {
        thread.interrupt();
    }
    this.tasks.clear();
    this.canceledGroupSet.clear();
}

From source file:org.apache.axis.components.threadpool.ThreadPool.java

/**
 * Forcefully interrupt all workers/*from   ww w  .j a  v  a2  s . c  o m*/
 */
public void interruptAll() {
    if (log.isDebugEnabled()) {
        log.debug("Enter: ThreadPool::interruptAll");
    }
    synchronized (threads) {
        for (Iterator i = threads.values().iterator(); i.hasNext();) {
            Thread t = (Thread) i.next();
            t.interrupt();
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Exit: ThreadPool::interruptAll");
    }
}

From source file:pl.chilldev.commons.jsonrpc.daemon.AbstractApplication.java

/**
 * Stops listeners.//from w  w  w  .ja v a 2s .  c o  m
 */
@Override
public void stop() {
    this.logger.info("Stopping");

    // stop all threads
    this.threads.forEach(Listener::release);

    // wait for all threads
    for (Thread thread : this.threads) {
        try {
            // this is to make sure that thread don't hang on some I/O
            thread.interrupt();
            thread.join();
        } catch (InterruptedException error) {
            this.logger.error("Had to interrupt while waiting for thread \"{}\".", thread.getName(), error);
        }
    }
    // just to clean references
    this.threads.clear();
}