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:org.marketcetera.util.except.ExceptUtilsTest.java

private void swallowHelper(Exception ex, boolean interrupted) {
    assertEquals(interrupted, ExceptUtils.swallow(ex, TEST_CATEGORY,
            new I18NBoundMessage1P(TestMessages.MID_EXCEPTION, MID_MSG_PARAM)));
    assertEquals(interrupted, Thread.interrupted());
    assertSingleEvent(Level.WARN, TEST_CATEGORY, MID_MSG_EN, TEST_LOCATION);

    assertEquals(interrupted, ExceptUtils.swallow(ex));
    assertEquals(interrupted, Thread.interrupted());
    assertSingleEvent(Level.WARN, TEST_CATEGORY, "Caught throwable was not propagated", TEST_LOCATION);
}

From source file:at.ac.ait.ubicity.fileloader.FileLoader.java

/**
 * /*ww w .j av  a 2 s.co  m*/
 * This method is here for demo purposes only. It is not part of the required functionality for this class. 
 * 
 * 
 * @param args arg 0 = file, arg #1 = keyspace, arg #2 = server host name, arg #3 = batch size, arg #4 = number of time units to wait, arg #5 = time unit ( minute, second, hour,.. ) 
 * ( For now, tacitly assume we are on the default Cassandra 9160 port ). Clustering is not yet supported.
 */
public final static void main(String[] args) throws Exception {
    if (!(args.length == 6)) {
        usage();
        System.exit(1);
    }

    try {
        final File _f = new File(args[0]);

        URI uri = _f.toURI();
        String keySpaceName = args[1];
        final String host = args[2];
        final int batchSize = Integer.parseInt(args[3]);
        final int timeUnitCount = Integer.parseInt(args[4]);
        Delay timeUnit = timeUnitsFromCmdLine(args[5].toUpperCase());
        if (timeUnit == null)
            timeUnit = Delay.SECOND;
        long millisToWait = timeUnitCount * timeUnit.getMilliSeconds();
        useCache = true;
        while (true) {
            try {
                invigilate(uri, keySpaceName, host, batchSize, millisToWait);
                Thread.sleep(millisToWait);
            } catch (InterruptedException | Error any) {
                Thread.interrupted();
            } finally {

            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, e.toString());
    }
}

From source file:Test.java

private void createOrderingThread() {
    Thread orderingThread = new Thread(new Runnable() {
        public void run() {
            while (!Thread.interrupted()) {
                createRandomOrder();/*from   ww w.ja v a2  s  .  c  o  m*/
            }
        }
    });
    orderingThread.start();
    orderingThreads.add(orderingThread);
}

From source file:com.cooksys.httpserver.WorkerThread.java

@Override
public void run() {
    System.out.println("New connection thread");
    HttpContext context = new BasicHttpContext(null);
    try {/* w  w w .j av  a2s  .c o m*/
        while (!Thread.interrupted() && this.conn.isOpen()) {
            this.httpservice.handleRequest(this.conn, context);
            //System.out.println(httpservice.);
        }
    } catch (ConnectionClosedException ex) {
        System.err.println("Client closed connection");
    } catch (IOException ex) {
        System.err.println("I/O error: " + ex.getMessage());
    } catch (HttpException ex) {
        System.err.println("Unrecoverable HTTP protocol violation: " + ex.getMessage());
    } finally {
        try {
            this.conn.shutdown();
        } catch (IOException ignore) {
        }
    }
}

From source file:org.sbq.batch.tasks.LongRunningBatchTask.java

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    Date scheduledFireTime = (Date) chunkContext.getStepContext().getJobParameters().get("scheduledFireTime");
    System.out.println(">>>> LongRunningBatchTask.execute( " + scheduledFireTime.toString() + " )");
    int i = 0;//w w  w.  j a  v a 2  s .c o  m
    while (i < 600) // we don't pay attention if we are interrupted
    {
        i++;
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            Thread.interrupted();
        }
    }
    return RepeatStatus.FINISHED;
}

From source file:org.archive.crawler.frontier.BdbMultipleWorkQueuesTest.java

/**
 * Basic sanity checks for calculateInsertKey() -- ensure ordinal, cost,
 * and schedulingDirective have the intended effects, for ordinal values
 * up through 1/4th of the maximum (about 2^61).
 * /*  w w w .j  a v  a 2s .c  o  m*/
 * @throws URIException
 */
public void testCalculateInsertKey() throws URIException {
    while (Thread.interrupted()) {
        logger.warning("stray interrupt cleared");
    }

    for (long ordinalOrigin = 1; ordinalOrigin < Long.MAX_VALUE / 4; ordinalOrigin <<= 1) {
        CrawlURI curi1 = new CrawlURI(UURIFactory.getInstance("http://archive.org/foo"));
        curi1.setOrdinal(ordinalOrigin);
        curi1.setClassKey("foo");
        byte[] key1 = BdbMultipleWorkQueues.calculateInsertKey(curi1).getData();
        CrawlURI curi2 = new CrawlURI(UURIFactory.getInstance("http://archive.org/bar"));
        curi2.setOrdinal(ordinalOrigin + 1);
        curi2.setClassKey("foo");
        byte[] key2 = BdbMultipleWorkQueues.calculateInsertKey(curi2).getData();
        CrawlURI curi3 = new CrawlURI(UURIFactory.getInstance("http://archive.org/baz"));
        curi3.setOrdinal(ordinalOrigin + 2);
        curi3.setClassKey("foo");
        curi3.setSchedulingDirective(SchedulingConstants.HIGH);
        byte[] key3 = BdbMultipleWorkQueues.calculateInsertKey(curi3).getData();
        CrawlURI curi4 = new CrawlURI(UURIFactory.getInstance("http://archive.org/zle"));
        curi4.setOrdinal(ordinalOrigin + 3);
        curi4.setClassKey("foo");
        curi4.setPrecedence(2);
        byte[] key4 = BdbMultipleWorkQueues.calculateInsertKey(curi4).getData();
        CrawlURI curi5 = new CrawlURI(UURIFactory.getInstance("http://archive.org/gru"));
        curi5.setOrdinal(ordinalOrigin + 4);
        curi5.setClassKey("foo");
        curi5.setPrecedence(1);
        byte[] key5 = BdbMultipleWorkQueues.calculateInsertKey(curi5).getData();
        // ensure that key1 (with lower ordinal) sorts before key2 (higher
        // ordinal)
        assertTrue("lower ordinal sorting first (" + ordinalOrigin + ")",
                Key.compareKeys(key1, key2, null) < 0);
        // ensure that key3 (with HIGH scheduling) sorts before key2 (even
        // though
        // it has lower ordinal)
        assertTrue("lower directive sorting first (" + ordinalOrigin + ")",
                Key.compareKeys(key3, key2, null) < 0);
        // ensure that key5 (with lower cost) sorts before key4 (even though 
        // key4  has lower ordinal and same default NORMAL scheduling directive)
        assertTrue("lower cost sorting first (" + ordinalOrigin + ")", Key.compareKeys(key5, key4, null) < 0);
    }
}

From source file:core.com.qiniu.internal.SdkInputStream.java

/**
 * Aborts with subclass specific abortion logic executed if needed. Note the
 * interrupted status of the thread is cleared by this method.
 *
 * @throws AbortedException if found necessary.
 *//*from  w  w w.j a  va 2 s  .c  o  m*/
protected final void abortIfNeeded() {
    if (Thread.interrupted()) {
        try {
            abort(); // execute subclass specific abortion logic
        } catch (IOException e) {
            LogFactory.getLog(getClass()).debug("FYI", e);
        }
        throw new AbortedException();
    }
}

From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.InterruptableInputStream.java

private void abortIfInterrupted() throws IOException {
    if (Thread.interrupted()) {
        if (request != null) {
            request.abort();/* ww  w. ja  v  a  2  s.c  o m*/
        }
        throw new InterruptedIOException();
    }
}

From source file:net.sf.jabref.logic.remote.server.RemoteListenerServer.java

@Override
public void run() {
    try {/*from w w  w .ja  va  2 s  .  c o m*/
        while (!Thread.interrupted()) {
            try (Socket socket = serverSocket.accept()) {
                socket.setSoTimeout(ONE_SECOND_TIMEOUT);

                Protocol protocol = new Protocol(socket);
                protocol.sendMessage(Protocol.IDENTIFIER);
                String message = protocol.receiveMessage();
                protocol.close();
                if (message.isEmpty()) {
                    continue;
                }
                messageHandler.handleMessage(message);

            } catch (SocketException ex) {
                return;
            } catch (IOException e) {
                LOGGER.warn("RemoteListenerServer crashed", e);
            }
        }
    } finally {
        closeServerSocket();
    }
}

From source file:com.devoteam.srit.xmlloader.http.bio.BIOSocketClientHttp.java

public void run() {
    try {/*from w  w  w.  ja v  a 2 s  .  c o  m*/
        while (!Thread.interrupted() && clientConnection.isOpen()) {
            HttpResponse response = clientConnection.receiveResponseHeader();
            clientConnection.receiveResponseEntity(response);

            MsgHttp msgResponse = new MsgHttp(response);

            //
            // Get corresponding msgRequest to read transactionId
            //
            if (isValid) {
                MsgHttp msgRequest = requestsSent.take();
                msgResponse.setTransactionId(msgRequest.getTransactionId());
                msgResponse.setChannel(this.connHttp);
                msgResponse.setType(msgRequest.getType());
            }

            //
            // Callback vers la Stack generic
            //
            StackFactory.getStack(StackFactory.PROTOCOL_HTTP).receiveMessage(msgResponse);
        }
    } catch (Exception e) {
        if (requestsSent.isEmpty()) {
            GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, e,
                    "Exception in SocketClientHttp without pending messages");
        } else {
            GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, e,
                    "Exception in SocketClientHttp with pending messages");
        }
    }

    synchronized (this.connHttp) {
        try {
            restoreConnection();
        } catch (Exception e) {
            GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, e,
                    "Exception while trying to restore connection ", this.connHttp);
        }
    }
}