Example usage for java.lang InterruptedException toString

List of usage examples for java.lang InterruptedException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.iitb.cse.Utils.java

public static void requestLogFiles(final int clientsPerRound, final int roundGap, String[] clientList) {

    Constants.currentSession.setFetchingLogFiles(true);

    //        final int 
    Runnable run = new Runnable() {
        @Override//w w w.j  a v a  2s.c  om
        public void run() {

            try {
                int requested = 0;
                Enumeration<String> macList = Constants.currentSession.getGetLogFilefFilteredDevices().keys();
                while (macList.hasMoreElements()) {
                    String macAddr = macList.nextElement();
                    String json = Utils.getLogFilesJson(1);
                    DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr);
                    System.out.println("\nMac Addr : " + macAddr);
                    System.out.println("\nJson : " + json);
                    Thread sendData = new Thread(new SendData(1, d, 4, json));
                    sendData.start();
                    requested++;
                    if (requested == clientsPerRound) {
                        requested = 0;
                        try {
                            Thread.sleep(roundGap * 1000); // seconds
                        } catch (InterruptedException ex) {
                            System.out.println(ex.toString());
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("\nException ex" + ex.toString());
            }
        }
    };

    Thread t = new Thread(run);
    t.start();
    //        Constants.currentSession.setFetchingLogFiles(false);

    //            int totalClients = clientList.length;
    //            if (clientsPerRound >= Constants.currentSession.getGetLogFilefFilteredDevices().size()) {
    //
    //                Enumeration<String> macList = Constants.currentSession.getGetLogFilefFilteredDevices().keys();
    //                while (macList.hasMoreElements()) {
    //                    String macAddr = macList.nextElement();
    //                    String json = Utils.getLogFilesJson(1);
    //                    DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr);
    //                    System.out.println("\nMac Addr : " + macAddr);
    //                    System.out.println("\nJson : " + json);
    //                    Thread sendData = new Thread(new SendData(1, d, 4, json));
    //                    sendData.start();
    //                }
    //                for (String client : clientList) {
    //
    //                    String value[] = client.split("_");
    //                    int expID = Integer.parseInt(value[0]);
    //                    String macAddr = value[1];
    //                    String json = Utils.getLogFilesJson(expID);
    //                    DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr);
    //                    System.out.println("\nMac Addr : " + macAddr);
    //                    System.out.println("\nJson : " + json);
    //                    Thread sendData = new Thread(new SendData(expID, d, 4, json));
    //                    sendData.start();
    //                }
    //            } else {
    //
    //                int requested = 0;
    //
    //                Enumeration<String> macList = Constants.currentSession.getGetLogFilefFilteredDevices().keys();
    //                while (macList.hasMoreElements()) {
    //                    String macAddr = macList.nextElement();
    //                    String json = Utils.getLogFilesJson(1);
    //                    DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr);
    //                    System.out.println("\nMac Addr : " + macAddr);
    //                    System.out.println("\nJson : " + json);
    //                    Thread sendData = new Thread(new SendData(1, d, 4, json));
    //                    sendData.start();
    //                    requested++;
    //
    //                    if (requested == clientsPerRound) {
    //                        requested = 0;
    //                        try {
    //                            Thread.sleep(roundGap * 1000); // seconds
    //                        } catch (InterruptedException ex) {
    //                            System.out.println(ex.toString());
    //                        }
    //                    }
    //                }
    //                while (totalClients > 0) {
    //
    //                    if (totalClients > clientsPerRound) {
    //
    //                        for (int i = 0; i < clientsPerRound; i++) {
    //                            String value[] = clientList[index].split("_");
    //                            int expID = Integer.parseInt(value[0]);
    //                            String macAddr = value[1];
    //                            String json = Utils.getLogFilesJson(expID);
    //                            DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr);
    //                            System.out.println("\nMac Addr : " + macAddr);
    //                            System.out.println("\nJson : " + json);
    //                            Thread sendData = new Thread(new SendData(expID, d, 4, json));
    //                            sendData.start();
    //                            index++;
    //                        }
    //                        totalClients = totalClients - clientsPerRound;
    //                    } else {
    //
    //                        for (int i = 0; i < totalClients; i++) {
    //
    //                            String value[] = clientList[index].split("_");
    //                            int expID = Integer.parseInt(value[0]);
    //                            String macAddr = value[1];
    //                            String json = Utils.getLogFilesJson(expID);
    //                            DeviceInfo d = Constants.currentSession.getConnectedClients().get(macAddr);
    //                            System.out.println("\nMac Addr : " + macAddr);
    //                            System.out.println("\nJson : " + json);
    //                            Thread sendData = new Thread(new SendData(expID, d, 4, json));
    //                            sendData.start();
    //                            index++;
    //                        }
    //                        totalClients = 0;
    //                    }
    //
    //                    try {
    //                        Thread.sleep(roundGap * 1000); // seconds
    //                    } catch (InterruptedException ex) {
    //                        System.out.println(ex.toString());
    //                    }
    //                }
}

From source file:ThreadDemo.java

public void run() {
    try {/*from  w  ww.j a va  2 s  .c  o m*/
        while (true) {
            Thread.sleep(1000);
        }
    } catch (InterruptedException e) {
        System.out.println(e.toString());
    }
}

From source file:Main.java

public ThreadGroupDemo() {
    try {//from  w  w w.j a v  a2s.  c o m
        ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

        ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

        Thread t1 = new Thread(pGroup, this);
        System.out.println("Starting " + t1.getName());
        t1.start();

        Thread t2 = new Thread(cGroup, this);
        System.out.println("Starting " + t2.getName());
        t2.start();

        // block until the other threads finish
        t1.join();
        t2.join();

        // child group destroyed
        cGroup.destroy();
        System.out.println(cGroup.getName() + " destroyed");

        // parent group destroyed
        pGroup.destroy();
        System.out.println(pGroup.getName() + " destroyed");

    } catch (InterruptedException ex) {
        System.out.println(ex.toString());
    }
}

From source file:org.apache.hadoop.filecache.DistributedCache.java

private static Path localizeCache(Configuration conf, URI cache, long confFileStamp, CacheStatus cacheStatus,
        FileStatus fileStatus, boolean isArchive, Path currentWorkDir, boolean honorSymLinkConf)
        throws IOException {
    boolean doSymlink = honorSymLinkConf && getSymlink(conf);
    if (cache.getFragment() == null) {
        doSymlink = false;// w ww  .  ja va  2s. co  m
    }
    FileSystem fs = getFileSystem(cache, conf);
    String link = currentWorkDir.toString() + Path.SEPARATOR + cache.getFragment();
    File flink = new File(link);
    if (ifExistsAndFresh(conf, fs, cache, confFileStamp, cacheStatus, fileStatus)) {
        if (isArchive) {
            if (doSymlink) {
                if (!flink.exists())
                    FileUtil.symLink(cacheStatus.localLoadPath.toString(), link);
            }
            return cacheStatus.localLoadPath;
        } else {
            if (doSymlink) {
                if (!flink.exists())
                    FileUtil.symLink(cacheFilePath(cacheStatus.localLoadPath).toString(), link);
            }
            return cacheFilePath(cacheStatus.localLoadPath);
        }
    } else {
        // remove the old archive
        // if the old archive cannot be removed since it is being used by
        // another
        // job
        // return null
        if (cacheStatus.refcount > 1 && (cacheStatus.currentStatus == true))
            throw new IOException(
                    "Cache " + cacheStatus.localLoadPath.toString() + " is in use and cannot be refreshed");

        FileSystem localFs = FileSystem.getLocal(conf);
        localFs.delete(cacheStatus.localLoadPath, true);
        synchronized (baseDirSize) {
            Long dirSize = baseDirSize.get(cacheStatus.baseDir);
            if (dirSize != null) {
                dirSize -= cacheStatus.size;
                baseDirSize.put(cacheStatus.baseDir, dirSize);
            }
        }
        Path parchive = new Path(cacheStatus.localLoadPath, new Path(cacheStatus.localLoadPath.getName()));

        if (!localFs.mkdirs(cacheStatus.localLoadPath)) {
            throw new IOException("Mkdirs failed to create directory " + cacheStatus.localLoadPath.toString());
        }

        String cacheId = cache.getPath();
        fs.copyToLocalFile(new Path(cacheId), parchive);
        if (isArchive) {
            String tmpArchive = parchive.toString().toLowerCase();
            File srcFile = new File(parchive.toString());
            File destDir = new File(parchive.getParent().toString());
            if (tmpArchive.endsWith(".jar")) {
                RunJar.unJar(srcFile, destDir);
            } else if (tmpArchive.endsWith(".zip")) {
                FileUtil.unZip(srcFile, destDir);
            } else if (isTarFile(tmpArchive)) {
                FileUtil.unTar(srcFile, destDir);
            }
            // else will not do anyhting
            // and copy the file into the dir as it is
        }

        long cacheSize = FileUtil.getDU(new File(parchive.getParent().toString()));
        cacheStatus.size = cacheSize;
        synchronized (baseDirSize) {
            Long dirSize = baseDirSize.get(cacheStatus.baseDir);
            if (dirSize == null) {
                dirSize = Long.valueOf(cacheSize);
            } else {
                dirSize += cacheSize;
            }
            baseDirSize.put(cacheStatus.baseDir, dirSize);
        }

        // do chmod here
        try {
            FileUtil.chmod(parchive.toString(), "+x");
        } catch (InterruptedException e) {
            LOG.warn("Exception in chmod" + e.toString());
        }

        // update cacheStatus to reflect the newly cached file
        cacheStatus.currentStatus = true;
        cacheStatus.mtime = getTimestamp(conf, cache);
    }

    if (isArchive) {
        if (doSymlink) {
            if (!flink.exists())
                FileUtil.symLink(cacheStatus.localLoadPath.toString(), link);
        }
        return cacheStatus.localLoadPath;
    } else {
        if (doSymlink) {
            if (!flink.exists())
                FileUtil.symLink(cacheFilePath(cacheStatus.localLoadPath).toString(), link);
        }
        return cacheFilePath(cacheStatus.localLoadPath);
    }
}

From source file:org.deviceconnect.message.intent.impl.io.IntentHttpMessageParser.java

@Override
public HttpMessage parse() throws IOException, HttpException {

    long parseStart = System.currentTimeMillis();

    // wait for response, or response timeout
    // if SoTimeout is 0, infinite wait
    while (mResponseList.size() == 0
            && (mSoTimeout == 0 || mSoTimeout > System.currentTimeMillis() - parseStart)) {
        try {/*  ww  w.  j av  a 2s .c  o m*/
            Thread.sleep(WAIT_TIME);
        } catch (InterruptedException e) {
            mLogger.log(Level.FINE, e.toString(), e);
            throw new IOException(e);
        }
    }

    if (mResponseList.size() <= 0 && mSoTimeout <= System.currentTimeMillis() - parseStart) {
        throw new IOException("response timeout");
    }

    Intent intent = mResponseList.remove(0);

    DConnectMessage dmessage = IntentMessageFactory.getMessageFactory().newDConnectMessage(intent);
    HttpMessage message = HttpMessageFactory.getMessageFactory().newPackagedMessage(dmessage);
    HttpResponse response = (HttpResponse) message;

    return response;

}

From source file:copter.HCSR04.java

private void delay(int ms) {
    try {/*from w  w w.j av a2  s  .co m*/
        Thread.sleep(ms);
    } catch (InterruptedException e) {
        System.out.println(e.toString());
    }
}

From source file:copter.HCSR04.java

private void delay(int ms, int ns) {
    try {/*  ww w  . jav a  2  s  . c o m*/
        Thread.sleep(ms, ns);
    } catch (InterruptedException e) {
        System.out.println(e.toString());
    }
}

From source file:org.apache.hadoop.cifs.mapred.AutoProgressMapper.java

/**
 * Run the mapping process for this task, wrapped in an auto-progress system.
 *//*from  w w  w .j a  v a  2 s . c om*/
@Override
public void run(Context context) throws IOException, InterruptedException {
    ProgressThread thread = new ProgressThread(context, LOG);

    try {
        thread.setDaemon(true);
        thread.start();

        // use default run() method to actually drive the mapping.
        super.run(context);
    } finally {
        // Tell the progress thread to exit..
        LOG.debug("Instructing auto-progress thread to quit.");
        thread.signalShutdown();
        try {
            // And wait for that to happen.
            LOG.debug("Waiting for progress thread shutdown...");
            thread.join();
            LOG.debug("Progress thread shutdown detected.");
        } catch (InterruptedException ie) {
            LOG.warn("Interrupted when waiting on auto-progress thread: " + ie.toString(), ie);
        }
    }
}

From source file:org.powertac.samplebroker.core.BrokerPauseTest.java

/**
 * Normal msg sequence tsu ... tc./*  ww  w.  j a  va  2 s . c  o  m*/
 */
@Test
public void noPause() {
    try {
        Thread.sleep(2001); // 2.001 seconds
        // it's now the start of ts1
        TimeslotUpdate tsu = new TimeslotUpdate(baseTime.plus(2000), 2, 12);
        broker.handleMessage(tsu);
        assertEquals("correct time", baseTime.plus(TimeService.HOUR).getMillis(),
                timeService.getCurrentTime().getMillis());
        Thread.sleep(1000); // delay by half a timeslot
        TimeslotComplete tc = new TimeslotComplete(1);
        broker.handleMessage(tc);
        assertEquals("correct timeslot index", 1, broker.getTimeslotCompleted());
    } catch (InterruptedException e) {
        fail("interrupted " + e.toString());
    }
}

From source file:org.springframework.messaging.simp.broker.OrderedMessageSenderTests.java

@Test
public void test() throws InterruptedException {

    int start = 1;
    int end = 1000;

    AtomicInteger index = new AtomicInteger(start);
    AtomicReference<Object> result = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);

    this.channel.subscribe(message -> {
        int expected = index.getAndIncrement();
        Integer actual = (Integer) message.getHeaders().getOrDefault("seq", -1);
        if (actual != expected) {
            result.set("Expected: " + expected + ", but was: " + actual);
            latch.countDown();// w w w  .  jav a 2s .  c om
            return;
        }
        if (actual == 100 || actual == 200) {
            try {
                Thread.sleep(200);
            } catch (InterruptedException ex) {
                result.set(ex.toString());
                latch.countDown();
            }
        }
        if (actual == end) {
            result.set("Done");
            latch.countDown();
        }
    });

    for (int i = start; i <= end; i++) {
        SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
        accessor.setHeader("seq", i);
        accessor.setLeaveMutable(true);
        this.sender.send(MessageBuilder.createMessage("payload", accessor.getMessageHeaders()));
    }

    latch.await(10, TimeUnit.SECONDS);
    assertEquals("Done", result.get());
}