Example usage for java.lang InterruptedException InterruptedException

List of usage examples for java.lang InterruptedException InterruptedException

Introduction

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

Prototype

public InterruptedException() 

Source Link

Document

Constructs an InterruptedException with no detail message.

Usage

From source file:GeneralInterrupt.java

public void work() throws InterruptedException {
    while (true) {
        for (int i = 0; i < 100000; i++) {
            int j = i * 2;
        }/* w ww.  j av  a 2s  .com*/

        System.out.println("A isInterrupted()=" + Thread.currentThread().isInterrupted());

        if (Thread.interrupted()) {
            System.out.println("B isInterrupted()=" + Thread.currentThread().isInterrupted());
            throw new InterruptedException();
        }
    }
}

From source file:net.wimpi.telnetd.util.ReentrantLock.java

public boolean attempt(long msecs) throws InterruptedException {
    //log.debug("attempt()::" + Thread.currentThread().toString());
    if (Thread.interrupted())
        throw new InterruptedException();
    Thread caller = Thread.currentThread();
    synchronized (this) {
        if (caller == m_Owner) {
            ++m_Holds;/*from w  ww .j av  a2 s  .c  om*/
            return true;
        } else if (m_Owner == null) {
            m_Owner = caller;
            m_Holds = 1;
            return true;
        } else if (msecs <= 0)
            return false;
        else {
            long waitTime = msecs;
            long start = System.currentTimeMillis();
            try {
                for (;;) {
                    wait(waitTime);
                    if (caller == m_Owner) {
                        ++m_Holds;
                        return true;
                    } else if (m_Owner == null) {
                        m_Owner = caller;
                        m_Holds = 1;
                        return true;
                    } else {
                        waitTime = msecs - (System.currentTimeMillis() - start);
                        if (waitTime <= 0)
                            return false;
                    }
                }
            } catch (InterruptedException ex) {
                notify();
                throw ex;
            }
        }
    }
}

From source file:fr.gael.dhus.datastore.scanner.FileScanner.java

private void checkList(List<URLExt> list, String root) throws InterruptedException {
    if (isStopped())
        throw new InterruptedException();

    File root_file = new File(root);
    if (!root_file.exists())
        throw new UnsupportedOperationException("cannot access repository path \"" + root + "\".");

    boolean is_root_dir = root_file.isDirectory();
    String uri;//from ww w .  ja v a2s.co  m
    URL url;
    try {
        url = root_file.toURI().toURL();
        uri = url.toExternalForm();
    } catch (MalformedURLException e) {
        throw new UnsupportedOperationException("Cannot convert file \"" + root + "\" to URI.", e);
    }
    DrbNode item = DrbFactory.openURI(uri);
    scannedFiles++;
    boolean accept = matches(item);

    if (accept) {
        list.add(new URLExt(url, is_root_dir));
        retrievedFile++;
    }

    if ((!accept || isForceNavigate()) && is_root_dir) {
        File[] files = root_file.listFiles();
        if (files == null) {
            logger.error("Directory " + root_file + " not accessible.");
            return;
        }
        for (File f : files)
            checkList(list, f.getPath());
    }
}

From source file:org.Cherry.Modules.Web.Engine.RequestWorker.java

@Override
public void run() {
    log.debug("New connection thread");

    final HttpContext context = new BasicHttpContext(null);

    while (getHttpServerConnection().isOpen()) {
        if (Thread.interrupted())
            throw new IllegalStateException(new InterruptedException());

        try {//w ww .  j  ava  2  s.c o  m
            getHttpService().handleRequest(getHttpServerConnection(), context);
        } catch (final ConnectionClosedException err) {
            log.debug("[{}]", err.getMessage());
            break;
        } catch (final Throwable err) {
            log.error(err.getMessage(), err);
            break;
        }
    }

    getMetricsService().examine(getHttpServerConnection());
}

From source file:nuclei.task.Task.java

/**
 * Execute the Task, if the ContextHandle is still valid
 *
 * @hide/*from  ww w .  j a v  a  2s.  co m*/
 */
public final void run() {
    currentThread = Thread.currentThread();
    try {
        if (interrupted.get()) {
            onException(new InterruptedException());
            return;
        }
        Context context = handle.get();
        if (context != null) {
            try {
                run(context);
                if (!resultSet)
                    throw new IllegalStateException("onComplete and onException not called, one is required");
            } catch (Exception err) {
                LOG.e("unhandled exception", err);
                onException(err);
            } catch (Throwable err) {
                LOG.e("unhandled throwable", err);
                onException(new Exception(err));
            }
        } else {
            LOG.i("Context Handle is released, not running task");
        }
    } finally {
        currentThread = null;
    }
}

From source file:org.roda_project.commons_ip.utils.Utils.java

public static Path copyResourceFromClasspathToDir(Class<?> resourceClass, Path dir, String resourceTempSuffix,
        String resourcePath) throws IOException, InterruptedException {
    try {//  w  w  w .j a va  2  s.  c om
        Path resource = Files.createTempFile(dir, "", resourceTempSuffix);
        InputStream inputStream = resourceClass.getResourceAsStream(resourcePath);
        OutputStream outputStream = Files.newOutputStream(resource);
        IOUtils.copy(inputStream, outputStream);
        inputStream.close();
        outputStream.close();
        return resource;
    } catch (ClosedByInterruptException e) {
        throw new InterruptedException();
    }
}

From source file:ca.uvic.chisel.logging.eclipse.internal.network.LogUploadRunnable.java

public void run(IProgressMonitor sendMonitor) throws InterruptedException, InvocationTargetException {
    File[] filesToUpload = log.getCategory().getFilesToUpload();
    sendMonitor.beginTask("Uploading Log " + log.getCategory().getName(), filesToUpload.length);
    LoggingCategory category = log.getCategory();
    IMemento memento = category.getMemento();
    for (File file : filesToUpload) {
        if (sendMonitor.isCanceled()) {
            throw new InterruptedException();
        }/* w w  w .j  a  va  2s. c  o  m*/
        PostMethod post = new PostMethod(category.getURL().toString());

        try {
            Part[] parts = { new StringPart("KIND", "workbench-log"),
                    new StringPart("CATEGORY", category.getCategoryID()),
                    new StringPart("USER", WorkbenchLoggingPlugin.getDefault().getLocalUser()),
                    new FilePart("WorkbenchLogger", file.getName(), file, "application/zip", null) };
            post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
            HttpClient client = new HttpClient();
            int status = client.executeMethod(post);
            String resp = getData(post.getResponseBodyAsStream());
            if (status != 200 || !resp.startsWith("Status: 200 Success")) {
                IOException ex = new IOException(resp);
                throw (ex);
            }
            memento.putString("lastUpload", file.getName());
            file.delete();
        } catch (IOException e) {
            throw new InvocationTargetException(e);
        } finally {
            sendMonitor.worked(1);
        }
    }
    sendMonitor.done();
}

From source file:gr.aueb.dmst.istlab.unixtools.actions.impl.ExecuteCustomCommandAction.java

@Override
public void execute(ActionExecutionCallback<DataActionResult<InputStream>> callback)
        throws IOException, InterruptedException {
    DataActionResult<InputStream> result;
    List<String> arguments = EclipsePluginUtil.getSystemShellInfo();

    ProcessBuilder pb;//  w  w  w. j  a  va 2s  .  c om

    if (SystemUtils.IS_OS_WINDOWS) {
        pb = new ProcessBuilder(arguments.get(0), arguments.get(1), arguments.get(2) + "\"cd "
                + this.commandToExecute.getShellDirectory() + ";" + this.commandToExecute.getCommand() + "\"");
    } else {
        arguments.add(this.commandToExecute.getCommand());
        pb = new ProcessBuilder(arguments);
        pb.directory(new File(this.commandToExecute.getShellDirectory()));
    }
    pb.redirectErrorStream(true);

    Process p;
    try {
        p = pb.start();
        p.waitFor();
        InputStream cmdStream = p.getInputStream();
        result = new DataActionResult<>(cmdStream);
    } catch (IOException e) {
        logger.fatal("IO problem occurred while executing the command");
        result = new DataActionResult<>(e);
        throw new IOException(e);
    } catch (InterruptedException e) {
        logger.fatal("The current thread has been interrupted while executing the command");
        result = new DataActionResult<>(e);
        throw new InterruptedException();
    }

    callback.onCommandExecuted(result);
}

From source file:com.appunite.socketio.SocketIO.java

void connectToTransport(ConnectionResult connect) throws InterruptedException {
    this.mConnect = connect;
    try {//from w ww.j a v  a2s. c  o m
        synchronized (mInterruptionLock) {
            if (mInterrupted)
                throw new InterruptedException();
            mIfSocketStarted = true;
        }
        mWebSocket.connect(connect.socketUri);
    } catch (UnknownHostException e) {
        error(e);
    } catch (IOException e) {
        error(e);
    } catch (WrongWebsocketResponse e) {
        error(e);
    } finally {
        synchronized (mInterruptionLock) {
            mIfSocketStarted = false;
        }
    }
}

From source file:net.technicpack.utilslib.ZipUtils.java

private static void unzipEntry(ZipFile zipFile, ZipEntry entry, File outputFile)
        throws IOException, InterruptedException {
    byte[] buffer = new byte[2048];
    BufferedInputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
    try {/*from w w w.  ja  v  a 2 s .com*/
        int length;
        while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
            outputStream.write(buffer, 0, length);
        }
    } catch (ClosedByInterruptException ex) {
        throw new InterruptedException();
    } finally {
        IOUtils.closeQuietly(outputStream);
        IOUtils.closeQuietly(inputStream);
    }
}