Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:edu.pitt.csb.stability.StabilityUtils.java

public static void main(String[] args) {
    String fn = "/Users/ajsedgewick/tetrad_mgm_runs/run2/networks/DAG_0_graph.txt";
    Graph trueGraph = GraphUtils.loadGraphTxt(new File(fn));
    DataSet ds = null;/* w  ww . j  ava  2s  . c  o m*/
    try {
        ds = MixedUtils.loadData("/Users/ajsedgewick/tetrad_mgm_runs/run2/data/", "DAG_0_data.txt");
    } catch (Throwable t) {
        t.printStackTrace();
    }

    double lambda = .1;
    SearchWrappers.MGMWrapper mgm = new SearchWrappers.MGMWrapper(new double[] { lambda, lambda, lambda });
    long start = System.currentTimeMillis();
    DoubleMatrix2D xi = StabilitySearch(ds, mgm, 8, 200);
    long end = System.currentTimeMillis();
    System.out.println("Not parallel: " + ((end - start) / 1000.0));

    start = System.currentTimeMillis();
    DoubleMatrix2D xi2 = StabilitySearchPar(ds, mgm, 8, 200);
    end = System.currentTimeMillis();
    System.out.println("Parallel: " + ((end - start) / 1000.0));

    System.out.println(xi);
    System.out.println(xi2);
}

From source file:awskinesis.AmazonKinesisApplicationSample.java

public static void main(String[] args) throws Exception {
    init();//  w ww .ja  v a  2  s  . co m

    if (args.length == 1 && "delete-resources".equals(args[0])) {
        deleteResources();
        return;
    }

    String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
    KinesisClientLibConfiguration kinesisClientLibConfiguration = new KinesisClientLibConfiguration(
            SAMPLE_APPLICATION_NAME, SAMPLE_APPLICATION_STREAM_NAME, credentialsProvider, workerId)
                    .withRegionName("cn-north-1");
    kinesisClientLibConfiguration.withInitialPositionInStream(SAMPLE_APPLICATION_INITIAL_POSITION_IN_STREAM);

    IRecordProcessorFactory recordProcessorFactory = new AmazonKinesisApplicationRecordProcessorFactory();
    final Worker worker = new Worker(recordProcessorFactory, kinesisClientLibConfiguration);

    System.out.printf("Running %s to process stream %s as worker %s...\n", SAMPLE_APPLICATION_NAME,
            SAMPLE_APPLICATION_STREAM_NAME, workerId);

    int exitCode = 0;
    try {
        worker.run();
    } catch (Throwable t) {
        System.err.println("Caught throwable while processing data.");
        t.printStackTrace();
        exitCode = 1;
    }

    // add a shutdown hook to stop the server
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            LOG.info("########### shoutdown begin....");
            worker.shutdown();

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            LOG.info("########### shoutdown end....");
        }
    }));

    System.exit(exitCode);
}

From source file:TransformThread.java

/**
 * Usage:/*from  w w  w .  ja va  2 s .  c om*/
 * java TransformThread
 */
public static void main(String argv[]) {
    try {
        initSystemProperties();
        initThreads();

        for (int count = 0; count < NUM_THREADS; count++) {
            INSTANCES[count].m_thread.start();
        }
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:com.google.api.services.samples.prediction.cmdline.PredictionSample.java

public static void main(String[] args) {
    try {/*from   w  w w  .ja v a2  s . com*/
        // initialize the transport
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();

        // initialize the data store factory
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

        // authorization
        Credential credential = authorize();

        // set up global Prediction instance
        client = new Prediction.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME).build();

        //      System.out.println("Success! Now add code here.");
        train(client);

        String sample = "This version of the simple language";
        predict(client, sample);

    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(1);
}

From source file:jena.RuleMap.java

/**
 * General command line utility to process one RDF file into another
 * by application of a set of forward chaining rules. 
 * <pre>/*from  www. j a  v a  2s  .c o m*/
 * Usage:  RuleMap [-il inlang] [-ol outlang] -d infile rulefile
 * </pre>
 */
public static void main(String[] args) {
    try {

        // Parse the command line
        String usage = "Usage:  RuleMap [-il inlang] [-ol outlang] [-d] rulefile infile (- for stdin)";
        final CommandLineParser parser = new DefaultParser();
        Options options = new Options().addOption("il", "inputLang", true, "input language")
                .addOption("ol", "outputLang", true, "output language").addOption("d", "Deductions only?");
        CommandLine cl = parser.parse(options, args);
        final List<String> filenameArgs = cl.getArgList();
        if (filenameArgs.size() != 2) {
            System.err.println(usage);
            System.exit(1);
        }

        String inLang = cl.getOptionValue("inputLang");
        String fname = filenameArgs.get(1);
        Model inModel = null;
        if (fname.equals("-")) {
            inModel = ModelFactory.createDefaultModel();
            inModel.read(System.in, null, inLang);
        } else {
            inModel = FileManager.get().loadModel(fname, inLang);
        }

        String outLang = cl.hasOption("outputLang") ? cl.getOptionValue("outputLang") : "N3";

        boolean deductionsOnly = cl.hasOption('d');

        // Fetch the rule set and create the reasoner
        BuiltinRegistry.theRegistry.register(new Deduce());
        Map<String, String> prefixes = new HashMap<>();
        List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
        Reasoner reasoner = new GenericRuleReasoner(rules);

        // Process
        InfModel infModel = ModelFactory.createInfModel(reasoner, inModel);
        infModel.prepare();
        infModel.setNsPrefixes(prefixes);

        // Output
        try (PrintWriter writer = new PrintWriter(System.out)) {
            if (deductionsOnly) {
                Model deductions = infModel.getDeductionsModel();
                deductions.setNsPrefixes(prefixes);
                deductions.setNsPrefixes(inModel);
                deductions.write(writer, outLang);
            } else {
                infModel.write(writer, outLang);
            }
        }
    } catch (Throwable t) {
        System.err.println("An error occured: \n" + t);
        t.printStackTrace();
    }
}

From source file:asm.FindCallers.java

public static void main(String... args) {

    OutputStream os = null;/*from  www  .j a  v  a  2s  . c o m*/

    try {
        FindAnnotationWalker w = new FindAnnotationWalker();

        FindCallers cl = w.walk(args[0], args[1]);

        for (Annotated a : cl.annotated)
            System.out.println(a);

        System.out.println("Start CSV");

        os = new FileOutputStream(args[2]);

        for (Annotated a : cl.annotated) {
            if (!a.isPublic) {
                String line = String.format("%s\t%s\t%s\t%s\t%s\t%s\n", "no", "", "", a.className, a.name,
                        a.getTarget());

                os.write(line.getBytes("UTF-8"));
            }
        }

        for (Invocation i : cl.invocations) {
            if (cl.annotatedMap.containsKey(i.getTarget())) {
                for (Annotated a : cl.annotatedMap.get(i.getTarget())) {
                    String ok = "";

                    if (i.sourceClassName.endsWith("Cmd") || i.sourceClassName.endsWith("Test")
                            || i.sourceClassName.contains("/test/")) {
                        ok = "ok";
                    }

                    if (i.sourceClassName.equals(a.className)) {
                        ok = "no";
                    }

                    if (ok.equals("") && i.sourceBaseName.equals(a.baseName)
                            && !i.sourceClassName.equals(a.className)) {
                        /* Source and dest are different and they are both have the 
                         * same parent, so they obviously one isn't a child of the other
                         */
                        ok = "ok";
                    }

                    String line = String.format("%s\t%s\t%s\t%s\t%s\t%s\n", ok, i.sourceClassName,
                            i.sourceMethodName, a.className, a.name, a.getTarget());

                    os.write(line.getBytes("UTF-8"));
                }
            }
        }

        System.out.println("Done CSV");
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(os);
    }

}

From source file:at.tfr.securefs.client.SecurefsClient.java

public static void main(String[] args) throws Exception {

    SecurefsClient client = new SecurefsClient();
    try {/*  www.  ja va 2  s . c  o  m*/
        client.parse(args);

        if (client.asyncTest) {
            ExecutorService executor = Executors.newFixedThreadPool(client.threads);
            for (int i = 0; i < client.threads; i++) {
                executor.submit(client);
            }
            executor.shutdown();
            executor.awaitTermination(10, TimeUnit.MINUTES);
        } else {
            client.run();
        }

    } catch (Throwable e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp(SecurefsClient.class.getSimpleName(), client.options);
        e.printStackTrace();
    }
}

From source file:herddb.server.ServerMain.java

public static void main(String... args) {
    try {/*from   w ww . jav  a 2s.c  o m*/
        LOG.log(Level.INFO, "Starting HerdDB version {0}", herddb.utils.Version.getVERSION());
        Properties configuration = new Properties();

        boolean configFileFromParameter = false;
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (!arg.startsWith("-")) {
                File configFile = new File(args[i]).getAbsoluteFile();
                LOG.log(Level.INFO, "Reading configuration from {0}", configFile);
                try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile),
                        StandardCharsets.UTF_8)) {
                    configuration.load(reader);
                }
                configFileFromParameter = true;
            } else if (arg.equals("--use-env")) {
                System.getenv().forEach((key, value) -> {
                    System.out.println("Considering env as system property " + key + " -> " + value);
                    System.setProperty(key, value);
                });
            } else if (arg.startsWith("-D")) {
                int equals = arg.indexOf('=');
                if (equals > 0) {
                    String key = arg.substring(2, equals);
                    String value = arg.substring(equals + 1);
                    System.setProperty(key, value);
                }
            }
        }
        if (!configFileFromParameter) {
            File configFile = new File("conf/server.properties").getAbsoluteFile();
            LOG.log(Level.INFO, "Reading configuration from {0}", configFile);
            if (configFile.isFile()) {
                try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile),
                        StandardCharsets.UTF_8)) {
                    configuration.load(reader);
                }
            }
        }

        System.getProperties().forEach((k, v) -> {
            String key = k + "";
            if (!key.startsWith("java") && !key.startsWith("user")) {
                configuration.put(k, v);
            }
        });

        LogManager.getLogManager().readConfiguration();

        Runtime.getRuntime().addShutdownHook(new Thread("ctrlc-hook") {

            @Override
            public void run() {
                System.out.println("Ctrl-C trapped. Shutting down");
                ServerMain _brokerMain = runningInstance;
                if (_brokerMain != null) {
                    _brokerMain.close();
                }
            }

        });
        runningInstance = new ServerMain(configuration);
        runningInstance.start();

        runningInstance.join();

    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
}

From source file:at.tfr.securefs.client.SecurefsFileServiceClient.java

public static void main(String[] args) throws Exception {

    SecurefsFileServiceClient client = new SecurefsFileServiceClient();
    try {/*from  w  w w .j  a v  a2 s  .  c  o m*/
        client.parse(args);

        if (client.asyncTest) {
            ExecutorService executor = Executors.newFixedThreadPool(client.threads);
            for (int i = 0; i < client.threads; i++) {
                executor.submit(client);
            }
            executor.shutdown();
            executor.awaitTermination(10, TimeUnit.MINUTES);
        } else {
            client.run();
        }

    } catch (Throwable e) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp(SecurefsFileServiceClient.class.getSimpleName(), client.options);
        e.printStackTrace();
    }
}

From source file:com.twitter.distributedlog.tools.Tool.java

public static void main(String args[]) {
    int rc = -1;//from www  .j  a v a  2s. c o m
    if (args.length <= 0) {
        System.err.println("No tool to run.");
        System.err.println("");
        System.err.println("Usage : Tool <tool_class_name> <options>");
        System.exit(-1);
    }
    String toolClass = args[0];
    try {
        Tool tool = ReflectionUtils.newInstance(toolClass, Tool.class);
        String[] newArgs = new String[args.length - 1];
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
        rc = tool.run(newArgs);
    } catch (Throwable t) {
        System.err.println("Fail to run tool " + toolClass + " : ");
        t.printStackTrace();
    }
    System.exit(rc);
}