Example usage for java.lang InterruptedException printStackTrace

List of usage examples for java.lang InterruptedException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:edu.umn.cs.spatialHadoop.visualization.MultilevelPlot.java

public static Job plot(Path[] inPaths, Path outPath, Class<? extends Plotter> plotterClass,
        OperationsParams params) throws IOException, InterruptedException, ClassNotFoundException {
    if (params.getBoolean("showmem", false)) {
        // Run a thread that keeps track of used memory
        Thread memThread = new Thread(new Thread() {
            @Override/*from   w  w  w. j  a  v a 2 s  .  c om*/
            public void run() {
                Runtime runtime = Runtime.getRuntime();
                while (true) {
                    try {
                        Thread.sleep(60000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    runtime.gc();
                    LOG.info("Memory usage: "
                            + ((runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024 * 1024)) + "GB.");
                }
            }
        });
        memThread.setDaemon(true);
        memThread.start();
    }

    // Decide how to run it based on range of levels to generate
    String[] strLevels = params.get("levels", "7").split("\\.\\.");
    int minLevel, maxLevel;
    if (strLevels.length == 1) {
        minLevel = 0;
        maxLevel = Integer.parseInt(strLevels[0]) - 1;
    } else {
        minLevel = Integer.parseInt(strLevels[0]);
        maxLevel = Integer.parseInt(strLevels[1]);
    }
    // Create an output directory that will hold the output of the two jobs
    FileSystem outFS = outPath.getFileSystem(params);
    outFS.mkdirs(outPath);

    Job runningJob = null;
    if (OperationsParams.isLocal(params, inPaths)) {
        // Plot local
        plotLocal(inPaths, outPath, plotterClass, params);
    } else {
        int maxLevelWithFlatPartitioning = params.getInt(FlatPartitioningLevelThreshold, 4);
        if (minLevel <= maxLevelWithFlatPartitioning) {
            OperationsParams flatPartitioning = new OperationsParams(params);
            flatPartitioning.set("levels", minLevel + ".." + Math.min(maxLevelWithFlatPartitioning, maxLevel));
            flatPartitioning.set("partition", "flat");
            LOG.info("Using flat partitioning in levels " + flatPartitioning.get("levels"));
            runningJob = plotMapReduce(inPaths, new Path(outPath, "flat"), plotterClass, flatPartitioning);
        }
        if (maxLevel > maxLevelWithFlatPartitioning) {
            OperationsParams pyramidPartitioning = new OperationsParams(params);
            pyramidPartitioning.set("levels",
                    Math.max(minLevel, maxLevelWithFlatPartitioning + 1) + ".." + maxLevel);
            pyramidPartitioning.set("partition", "pyramid");
            LOG.info("Using pyramid partitioning in levels " + pyramidPartitioning.get("levels"));
            runningJob = plotMapReduce(inPaths, new Path(outPath, "pyramid"), plotterClass,
                    pyramidPartitioning);
        }
        // Write a new HTML file that displays both parts of the pyramid
        // Add an HTML file that visualizes the result using Google Maps
        LineReader templateFileReader = new LineReader(
                MultilevelPlot.class.getResourceAsStream("/zoom_view.html"));
        PrintStream htmlOut = new PrintStream(outFS.create(new Path(outPath, "index.html")));
        Text line = new Text();
        while (templateFileReader.readLine(line) > 0) {
            String lineStr = line.toString();
            lineStr = lineStr.replace("#{TILE_WIDTH}", Integer.toString(params.getInt("tilewidth", 256)));
            lineStr = lineStr.replace("#{TILE_HEIGHT}", Integer.toString(params.getInt("tileheight", 256)));
            lineStr = lineStr.replace("#{MAX_ZOOM}", Integer.toString(maxLevel));
            lineStr = lineStr.replace("#{MIN_ZOOM}", Integer.toString(minLevel));
            lineStr = lineStr.replace("#{TILE_URL}", "(zoom <= " + maxLevelWithFlatPartitioning
                    + "? 'flat' : 'pyramid')+('/tile-' + zoom + '-' + coord.x + '-' + coord.y + '.png')");

            htmlOut.println(lineStr);
        }
        templateFileReader.close();
        htmlOut.close();
    }

    return runningJob;
}

From source file:de.prozesskraft.pkraft.Manager.java

/**
 * startet einen thread, der zeitgesteuert aufwacht und den prozess weiterschiebt
 *//*from w  w  w.java2  s. c  om*/
private static void startZyklischerThread(int initialWaitSecond) {
    // falls dieser thread von hier aus gestartet wird, soll kurz gewartet werden
    try {
        Thread.sleep(initialWaitSecond * 1000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // einen timer thread erstellen, der regelmaessig den prozess aufweckt, auch wenn sehr langlaufende steps gerade aktiv sind
    new Thread(new Runnable() {
        public void run() {

            // flag, ob dieser thread einen neuen gestartet hat
            boolean spawn = false;

            System.err.println(new Timestamp(System.currentTimeMillis()) + ": ---- alternative thread: start");
            while (!exit && !spawn) {

                long tatsaechlicheSleepDauer = (long) (factorSleepBecauseOfLoadAverage
                        * ((loopMinutes * 60 * 1000) + fuzzyness));
                try {
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: sleeping " + tatsaechlicheSleepDauer / 1000
                            + " seconds (loopMinutes=" + loopMinutes + ", faktorSleepBecauseOfLoadAverage="
                            + factorSleepBecauseOfLoadAverage + ", fuzzyness=" + fuzzyness + ")");
                    Thread.sleep(tatsaechlicheSleepDauer);
                } catch (NumberFormatException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                // war der letzte zugriff laenger als der haelfte der regulaeren wartezeit her? Dann Prozess pushen
                if ((System.currentTimeMillis() - lastRun) > (0.5 * tatsaechlicheSleepDauer)) {
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: last process push has been MORE than 0.5 * "
                            + tatsaechlicheSleepDauer / 1000 + " seconds ago at " + new Timestamp(lastRun));
                    System.err.println(
                            new Timestamp(System.currentTimeMillis()) + ": ---- alternative thread: waking up");

                    if (watcherThread != null) {
                        System.err.println(new Timestamp(System.currentTimeMillis())
                                + ": ---- alternative thread: interrupting watcherThread");

                        watcherThread.interrupt();
                        watcherThread = null;
                    }

                    // ein neuer 
                    startZyklischerThread(5);
                    spawn = true;

                    pushProcessAsFarAsPossible(line.getOptionValue("instance"), false);

                    System.err.println(
                            new Timestamp(System.currentTimeMillis()) + ": ----- alternative thread: end");
                } else {
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: last process push has been LESS than 0.5 * "
                            + tatsaechlicheSleepDauer / 1000 + " seconds ago at " + new Timestamp(lastRun));
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: going to sleep again");

                }

            }

            // thread beenden
            System.err.println(new Timestamp(System.currentTimeMillis()) + ": ---- alternative thread: exit");
        }
    }).start();
}

From source file:ThreadX.java

public void run() {
    try {/*  ww  w .  j a va 2 s  . c  o  m*/
        while (true) {
            Thread.sleep(2000);
            System.out.println("Hello");
        }
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public void run() {
    System.out.println("Thread started");
    while (keepRunning) {
        try {/*ww  w .j  av a2s .  c  om*/
            System.out.println("Going to sleep");
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println("Thread stopped");
}

From source file:Main.java

public void run() {
    int i = count.incrementAndGet();
    myValue = i;//from  w  w w  .ja v  a 2  s.c o  m
    cdl1.countDown();
    try {
        cdl1.await();
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
    if (myValue != i)
        System.out.println("Bar not equal to i");
    else
        System.out.println("Bar equal to i");
}

From source file:Main.java

@Override
public void run() {
    try {/*w  ww  .  ja  v a2s.com*/
        Main.barrier.await();
        System.out.println("Let's play.");
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (BrokenBarrierException e) {
        e.printStackTrace();
    }
}

From source file:MyThread4.java

public void run() {
    try {/*from   w  w  w  .  ja v a2  s. co m*/
        while (true) {
            Thread.sleep(msec);
            System.out.println(str);
        }
    } catch (InterruptedException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

ContentPanel() {
    MediaTracker mt = new MediaTracker(this);
    bgimage = Toolkit.getDefaultToolkit().getImage("a.jpg");
    mt.addImage(bgimage, 0);// ww  w  .ja  v a  2 s .  c o  m
    try {
        mt.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:StartTogetherTask.java

@Override
public void run() {
    System.out.println(taskName + ":Initializing...");
    int sleepTime = rand.nextInt(5) + 1;
    try {/*w  w  w.ja  v  a 2 s  .c om*/
        Thread.sleep(sleepTime * 1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println(taskName + ":Initialized...");
    phaser.arriveAndAwaitAdvance();
    System.out.println(taskName + ":Started...");
}

From source file:Worker.java

public void run() {
    try {//  www  . jav a2 s  . c  o  m
        int workTime = random.nextInt(30) + 1;
        System.out.println("Thread #" + ID + " is going to work for " + workTime + "  seconds");
        Thread.sleep(workTime * 1000);
        System.out.println("Thread #" + ID + " is waiting at the barrier.");
        this.barrier.await();
        System.out.println("Thread #" + ID + " passed the barrier.");
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (BrokenBarrierException e) {
        System.out.println("Barrier is broken.");
    }
}