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:net.wimpi.telnetd.util.ReentrantLock.java

public void acquire() throws InterruptedException {
    //log.debug("acquire()::" + Thread.currentThread().toString());
    if (Thread.interrupted())
        throw new InterruptedException();
    Thread caller = Thread.currentThread();
    synchronized (this) {
        if (caller == m_Owner)
            ++m_Holds;/*from  w w w. j  a va 2  s  .  com*/
        else {
            try {
                while (m_Owner != null)
                    wait();
                m_Owner = caller;
                m_Holds = 1;
            } catch (InterruptedException ex) {
                notify();
                throw ex;
            }
        }
    }
}

From source file:PiInterrupt.java

private void calcPi(double accuracy) throws InterruptedException {

    latestPiEstimate = 0.0;/*from   w  w  w  .  j a  va  2 s .  co  m*/
    long iteration = 0;
    int sign = -1;

    while (Math.abs(latestPiEstimate - Math.PI) > accuracy) {

        if (Thread.interrupted()) {
            throw new InterruptedException();
        }

        iteration++;
        sign = -sign;
        latestPiEstimate += sign * 4.0 / ((2 * iteration) - 1);
    }
}

From source file:SwingWorkerProcessor.java

@Override
protected Integer doInBackground() throws Exception {
    int sum = 0;//from  w w  w.  jav a2s.  c  o m
    for (int counter = 1; counter <= iteration; counter++) {
        sum = sum + counter;
        this.publish(counter);
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        if (this.isCancelled()) {
            break;
        }
        Thread.sleep(intervalInMillis);
    }

    return sum;
}

From source file:httpscheduler.ConnectionHandlerThread.java

@Override
public void run() {
    System.out.println("\tNew connection handler thread is running");
    while (true) {

        HttpContext context = new BasicHttpContext(null);
        try {/*from   w ww . ja v a 2  s . co  m*/
            while (!Thread.interrupted() && this.conn.isOpen()) {
                this.httpservice.handleRequest(this.conn, context);
            }
        } 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:GeneralInterrupt.java

public void work() throws InterruptedException {
    while (true) {
        for (int i = 0; i < 100000; i++) {
            int j = i * 2;
        }//www.ja v  a2 s . c  o  m

        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 a v a  2s.c o m
            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:net.pms.util.ProcessUtil.java

public static int waitFor(Process p) {
    int exit = -1;

    try {//from  w ww .j a  va  2 s  . c  o m
        exit = p.waitFor();
    } catch (InterruptedException e) {
        Thread.interrupted();
    }

    return exit;
}

From source file:com.dc.tes.adapter.startup.remote.StartUpRemoteForRequest.java

public void run() {
    startAdapter(m_props);/* w  ww.j a v  a 2 s .  co m*/
    //  ??
    try {
        while (!Thread.interrupted()) {
            Thread.sleep(500);
        }
    } catch (InterruptedException e) {
        log.debug("?");
        shutdownAdapter();
    }
}

From source file:org.marketcetera.util.except.ExceptUtilsTest.java

private static void wrapHelper(Exception ex, boolean interruption) {
    I18NException out = ExceptUtils.wrap(ex, new I18NBoundMessage1P(TestMessages.MID_EXCEPTION, MID_MSG_PARAM));

    assertEquals(out.getDetail(), new I18NBoundMessage1P(TestMessages.MID_EXCEPTION, MID_MSG_PARAM),
            out.getI18NBoundMessage());/* w  w w .ja  v  a  2  s  .  c om*/
    assertEquals(ex, out.getCause());
    assertTrue(out instanceof I18NException);
    assertEquals(interruption, out instanceof I18NInterruptedException);
    assertEquals(interruption, Thread.interrupted());

    out = ExceptUtils.wrap(ex);
    assertEquals(ex, out.getCause());
    assertTrue(out instanceof I18NException);
    assertEquals(interruption, out instanceof I18NInterruptedException);
    assertEquals(interruption, Thread.interrupted());

    I18NRuntimeException outR = ExceptUtils.wrapRuntime(ex,
            new I18NBoundMessage1P(TestMessages.MID_EXCEPTION, MID_MSG_PARAM));
    assertEquals(outR.getDetail(), new I18NBoundMessage1P(TestMessages.MID_EXCEPTION, MID_MSG_PARAM),
            outR.getI18NBoundMessage());
    assertEquals(ex, outR.getCause());
    assertTrue(outR instanceof I18NRuntimeException);
    assertEquals(interruption, outR instanceof I18NInterruptedRuntimeException);
    assertEquals(interruption, Thread.interrupted());

    outR = ExceptUtils.wrapRuntime(ex);
    assertEquals(ex, outR.getCause());
    assertTrue(outR instanceof I18NRuntimeException);
    assertEquals(interruption, outR instanceof I18NInterruptedRuntimeException);
    assertEquals(interruption, Thread.interrupted());
}

From source file:io.gravitee.gateway.service.ratelimit.RateLimitUpdater.java

@Override
public void run() {
    while (!Thread.interrupted()) {
        try {//from  w w  w .  j a  v a  2s.co  m
            RateLimit rateLimit = queue.poll(getPollingTimeout(), TimeUnit.MILLISECONDS);
            if (rateLimit != null) {
                queue.offer(rateLimit);
            }

            while (!queue.isEmpty()) {
                rateLimit = queue.poll(getPollingTimeout(), TimeUnit.MILLISECONDS);
                if (rateLimit != null) {
                    delegateRateLimitRepository.save(rateLimit);
                }
            }
        } catch (InterruptedException ie) {

        } catch (Exception ex) {
            // Do nothing here
        }
    }
}