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:helma.swarm.SwarmSessionManager.java

public void shutdown() {
    if (adapter != null) {
        adapter.setListener(null);// w ww . j a  v  a 2  s . c  o  m
    }
    ChannelUtils.stopAdapter(app);

    if (runner != null) {
        Thread t = runner;
        runner = null;
        t.interrupt();
    }
}

From source file:org.blocks4j.reconf.client.config.update.ConfigurationRepositoryUpdater.java

private void interruptAll(List<? extends Thread> arg) {
    for (Thread t : arg) {
        try {/* w  ww.  j a  v  a2s .  c  o  m*/
            t.interrupt();
        } catch (Exception ignored) {
        }
    }
}

From source file:com.siberhus.tdfl.DflSimpleTest.java

@Test
public void testStopLoadingFile() throws DataFileLoaderException {
    Runnable dfl = new Runnable() {
        public void run() {
            employeeDfl.setDataFileProcessor(longRunningDfp);
            employeeDfl.setResource(new FileSystemResource(XLS_FILE_IN_NAME));
            try {
                employeeDfl.load();/*from ww  w.j  av a  2s . c  o  m*/
                Assert.fail();
            } catch (DataFileLoaderException e) {
                Assert.assertEquals(2, longRunningDfp.getSuccessCounter());
                Assert.assertEquals("Interrupt exception", "STOP", e.getMessage());
            }
        }
    };
    Thread thread = new Thread(dfl);
    thread.start();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    thread.interrupt();
}

From source file:org.apache.sling.testing.serversetup.jarexec.ShutdownHookSingleProcessDestroyer.java

public void destroyProcess(boolean waitForIt) {
    Process toDestroy = null;//w w  w .  j a  va2s .c om
    synchronized (this) {
        toDestroy = process;
        process = null;
    }

    if (toDestroy == null) {
        return;
    }

    toDestroy.destroy();

    if (waitForIt) {
        log.info("Waiting for destroyed process {} to exit (timeout={} seconds)", processInfo, timeoutSeconds);
        final Thread mainThread = Thread.currentThread();
        final Timer t = new Timer(true);
        final TimerTask task = new TimerTask() {
            @Override
            public void run() {
                mainThread.interrupt();
            }
        };
        t.schedule(task, timeoutSeconds * 1000L);
        try {
            toDestroy.waitFor();
            try {
                final int exit = toDestroy.exitValue();
                log.info("Process {} ended with exit code {}", processInfo, exit);
            } catch (IllegalStateException ise) {
                log.error("Failed to destroy process " + processInfo);
            }
        } catch (InterruptedException e) {
            log.error("Timeout waiting for process " + processInfo + " to exit");
        } finally {
            t.cancel();
        }
    }
}

From source file:com.meghnasoft.async.AbstractAsynchronousAction.java

/**
 * Allows interruption of the task if it is waiting.
 *
 *///  w  w  w. j a  va  2 s . co  m
public void interrupt() {
    final Thread t = threadVar.getThread();
    taskOutput = null;

    if (t != null) {
        t.interrupt();
    }
}

From source file:alluxio.cli.fs.command.DistributedLoadCommand.java

/**
 * Loads a file or directory in Alluxio space, makes it resident in memory.
 *
 * @param filePath The {@link AlluxioURI} path to load into Alluxio memory
 * @throws AlluxioException when Alluxio exception occurs
 * @throws IOException when non-Alluxio exception occurs
 *//*  w  w w.j  a v a  2s.  c  o  m*/
private void load(AlluxioURI filePath, int replication)
        throws AlluxioException, IOException, InterruptedException {
    URIStatus status = mFileSystem.getStatus(filePath);
    if (status.isFolder()) {
        List<URIStatus> statuses = mFileSystem.listStatus(filePath);
        for (URIStatus uriStatus : statuses) {
            AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
            load(newPath, replication);
        }
    } else {
        Thread thread = JobThriftClientUtils.createProgressThread(System.out);
        thread.start();
        try {
            JobThriftClientUtils.run(new LoadConfig(filePath.getPath(), replication), 3);
        } finally {
            thread.interrupt();
        }
    }
    System.out.println(filePath + " loaded");
}

From source file:pt.webdetails.cdc.plugin.HazelcastProcessLauncher.java

private void stopThread(Thread thread) {
    try {/*  www  .j  a  v a  2  s  .c  o  m*/
        if (thread != null) {
            thread.interrupt();
        }
    } catch (SecurityException se) {
        logger.error("Couldn't interrupt thread " + thread);
    }
}

From source file:ProgressBarDemo.java

/**
 * A new method that interrupts the worker thread.  Call this method
 * to force the worker to stop what it's doing.
 *//*w w w .  java  2s  .co m*/
public void interrupt() {
    Thread t = threadVar.get();
    if (t != null) {
        t.interrupt();
    }
    threadVar.clear();
}

From source file:org.energy_home.jemma.osgi.zgd.service.GatewayActivator.java

private void stopPollingTask() throws InterruptedException {
    // atomic because pollingThread is volatile
    Thread tmpThread = pollingThread;

    pollingThread = null;/*from w  w  w  .j a  v  a 2 s  .c  om*/

    if (tmpThread != null) {
        tmpThread.interrupt();
        tmpThread.join();
    }
}

From source file:org.gcaldaemon.core.Configurator.java

private static final void stopService(Thread service) {
    if (service != null) {
        try {/*from ww w.j a  va2s.  co  m*/
            service.interrupt();
        } catch (Exception ignored) {
        }
    }
}