Example usage for java.lang Runnable Runnable

List of usage examples for java.lang Runnable Runnable

Introduction

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

Prototype

Runnable

Source Link

Usage

From source file:gtu.log.finder.ExceptionLogFinderUI.java

/**
 * Auto-generated main method to display this JFrame
 *//*w ww.  ja v  a 2  s.c  o  m*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            ExceptionLogFinderUI inst = new ExceptionLogFinderUI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:gtu._work.ui.SqlCreaterUI.java

/**
 * Auto-generated main method to display this JFrame
 *///from   w w  w  .  ja  v a 2s  . c  o m
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            SqlCreaterUI inst = new SqlCreaterUI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:gtu._work.ui.JarFinderUI.java

/**
 * Auto-generated main method to display this JFrame
 *///from w w w  .  j  a v  a  2s  .c om
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JarFinderUI inst = new JarFinderUI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:br.usp.poli.lta.cereda.macro.Application.java

/**
 * Mtodo principal./*from w w w . j  av  a2 s  .  c o  m*/
 * @param args Argumentos de linha de comando.
 */
public static void main(String[] args) {

    // imprime banner
    System.out.println(StringUtils.repeat("-", 50));
    System.out.println(StringUtils.center("Expansor de macros", 50));
    System.out.println(StringUtils.repeat("-", 50));
    System.out.println(StringUtils.center("Laboratrio de linguagens e tcnicas adaptativas", 50));
    System.out.println(StringUtils.center("Escola Politcnica - Universidade de So Paulo", 50));
    System.out.println();

    try {

        // faz o parsing dos argumentos de linha de comando
        CLIParser parser = new CLIParser(args);
        Pair<String, File> pair = parser.parse();

        // se o par no  nulo,  possvel prosseguir com a expanso
        if (pair != null) {

            // obtm a expanso do texto fornecido na entrada
            String output = MacroExpander.parse(pair.getFirst());

            // se foi definido um arquivo de sada, grava a expanso do
            // texto nele, ou imprime o resultado no terminal, caso
            // contrrio
            if (pair.getSecond() != null) {
                FileUtils.writeStringToFile(pair.getSecond(), output, Charset.forName("UTF-8"));
                System.out.println("Arquivo gerado com sucesso.");
            } else {
                System.out.println(output);
            }

        } else {

            // verifica se a execuo corresponde a uma chamada ao editor
            // embutido de macros
            if (parser.isEditor()) {

                // cria o editor e exibe
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        DisplayUtils.init();
                        Editor editor = new Editor();
                        editor.setVisible(true);
                    }
                });
            }
        }
    } catch (Exception exception) {

        // ocorreu uma exceo, imprime a mensagem de erro
        System.out.println(StringUtils.rightPad("ERRO: ", 50, "-"));
        System.out.println(WordUtils.wrap(exception.getMessage(), 50));
        System.out.println(StringUtils.repeat(".", 50));
    }
}

From source file:javazoom.jlgui.player.amp.StandalonePlayer.java

/**
 * @param args/*  w w  w.  jav  a2  s  .co m*/
 */
public static void main(String[] args) {
    final StandalonePlayer player = new StandalonePlayer();
    player.parseParameters(args);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            player.loadUI();
            player.loadJS();
            player.loadPlaylist();
            player.boot();
        }
    });
}

From source file:com.linkedin.pinotdruidbenchmark.PinotThroughput.java

@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    if (args.length != 3 && args.length != 4) {
        System.err.println(/* w  w w.  ja  va 2  s  .c  o m*/
                "3 or 4 arguments required: QUERY_DIR, RESOURCE_URL, NUM_CLIENTS, TEST_TIME (seconds).");
        return;
    }

    File queryDir = new File(args[0]);
    String resourceUrl = args[1];
    final int numClients = Integer.parseInt(args[2]);
    final long endTime;
    if (args.length == 3) {
        endTime = Long.MAX_VALUE;
    } else {
        endTime = System.currentTimeMillis() + Integer.parseInt(args[3]) * MILLIS_PER_SECOND;
    }

    File[] queryFiles = queryDir.listFiles();
    assert queryFiles != null;
    Arrays.sort(queryFiles);

    final int numQueries = queryFiles.length;
    final HttpPost[] httpPosts = new HttpPost[numQueries];
    for (int i = 0; i < numQueries; i++) {
        HttpPost httpPost = new HttpPost(resourceUrl);
        String query = new BufferedReader(new FileReader(queryFiles[i])).readLine();
        httpPost.setEntity(new StringEntity("{\"pql\":\"" + query + "\"}"));
        httpPosts[i] = httpPost;
    }

    final AtomicInteger counter = new AtomicInteger(0);
    final AtomicLong totalResponseTime = new AtomicLong(0L);
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);

    for (int i = 0; i < numClients; i++) {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                    while (System.currentTimeMillis() < endTime) {
                        long startTime = System.currentTimeMillis();
                        CloseableHttpResponse httpResponse = httpClient
                                .execute(httpPosts[RANDOM.nextInt(numQueries)]);
                        httpResponse.close();
                        long responseTime = System.currentTimeMillis() - startTime;
                        counter.getAndIncrement();
                        totalResponseTime.getAndAdd(responseTime);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    executorService.shutdown();

    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() < endTime) {
        Thread.sleep(REPORT_INTERVAL_MILLIS);
        double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND;
        int count = counter.get();
        double avgResponseTime = ((double) totalResponseTime.get()) / count;
        System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: "
                + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms");
    }
}

From source file:com.digitalgeneralists.assurance.Application.java

public static void main(String[] args) {
    Logger logger = Logger.getLogger(Application.class);

    logger.info("App is starting.");

    Properties applicationProperties = new Properties();
    String applicationInfoFileName = "/version.txt";
    InputStream inputStream = Application.class.getResourceAsStream(applicationInfoFileName);
    applicationInfoFileName = null;//from  ww  w  .ja v a  2  s . c om

    try {
        if (inputStream != null) {
            applicationProperties.load(inputStream);

            Application.applicationShortName = applicationProperties.getProperty("name");
            Application.applicationName = applicationProperties.getProperty("applicationName");
            Application.applicationVersion = applicationProperties.getProperty("version");
            Application.applicationBuildNumber = applicationProperties.getProperty("buildNumber");

            applicationProperties = null;
        }
    } catch (IOException e) {
        logger.warn("Could not load application version information.", e);
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            logger.error("Couldn't close the application version input stream.");
        }
        inputStream = null;
    }

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        private Logger logger = Logger.getLogger(Application.class);

        public void run() {
            logger.info("Starting the Swing run thread.");

            try {
                Application.installDb();
            } catch (IOException e) {
                logger.fatal("Unable to install the application database.", e);
                System.exit(1);
            } catch (SQLException e) {
                logger.fatal("Unable to install the application database.", e);
                System.exit(1);
            }

            IApplicationUI window = null;
            ClassPathXmlApplicationContext springContext = null;
            try {
                springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml");
                StringBuffer message = new StringBuffer(256);
                logger.info(message.append("Spring Context: ").append(springContext));
                message.setLength(0);
                window = (IApplicationUI) springContext.getBean("ApplicationUI");
            } finally {
                if (springContext != null) {
                    springContext.close();
                }
                springContext = null;
            }

            if (window != null) {
                logger.info("Launching the window.");
                window.display();
            } else {
                logger.fatal("The main application window object is null.");
            }

            logger = null;
        }
    });
}

From source file:com.machinelinking.cli.loader.java

public static void main(String[] args) {
    if (args.length != 2) {
        System.err.println("Usage: $0 <config-file> <dump>");
        System.exit(1);// w w  w  .  j a  v a  2 s. c om
    }

    try {
        final File configFile = check(args[0]);
        final File dumpFile = check(args[1]);
        final Properties properties = new Properties();
        properties.load(FileUtils.openInputStream(configFile));

        final Flag[] flags = WikiPipelineFactory.getInstance().toFlags(getPropertyOrFail(properties,
                LOADER_FLAGS_PROP,
                "valid flags: " + Arrays.toString(WikiPipelineFactory.getInstance().getDefinedFlags())));
        final JSONStorageFactory jsonStorageFactory = MultiJSONStorageFactory
                .loadJSONStorageFactory(getPropertyOrFail(properties, LOADER_STORAGE_FACTORY_PROP, null));
        final String jsonStorageConfig = getPropertyOrFail(properties, LOADER_STORAGE_CONFIG_PROP, null);
        final URL prefixURL = readURL(getPropertyOrFail(properties, LOADER_PREFIX_URL_PROP,
                "expected a valid URL prefix like: http://en.wikipedia.org/"), LOADER_PREFIX_URL_PROP);

        final DefaultJSONStorageLoader[] loader = new DefaultJSONStorageLoader[1];
        final boolean[] finalReportProduced = new boolean[] { false };
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                if (!finalReportProduced[0] && loader[0] != null) {
                    System.err.println(
                            "Process interrupted. Partial loading report: " + loader[0].createReport());
                }
                System.err.println("Shutting down.");
            }
        }));

        final JSONStorageConfiguration storageConfig = jsonStorageFactory
                .createConfiguration(jsonStorageConfig);
        try (final JSONStorage storage = jsonStorageFactory.createStorage(storageConfig)) {
            loader[0] = new DefaultJSONStorageLoader(WikiPipelineFactory.getInstance(), flags, storage);

            final StorageLoaderReport report = loader[0].load(prefixURL,
                    FileUtil.openDecompressedInputStream(dumpFile));
            System.err.println("Loading report: " + report);
            finalReportProduced[0] = true;
        }
        System.exit(0);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:com.arpnetworking.tsdaggregator.TsdAggregator.java

/**
 * Entry point for Time Series Data (TSD) Aggregator.
 *
 * @param args the command line arguments
 *//*  w  ww.ja v a  2 s  .c  o  m*/
public static void main(final String[] args) {
    LOGGER.info("Launching tsd-aggregator");

    // Global initialization
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            LOGGER.error("Unhandled exception!", throwable);
        }
    });

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
            context.stop();
        }
    }));

    System.setProperty("org.vertx.logger-delegate-factory-class-name",
            "org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory");

    // Run the tsd aggregator
    if (args.length != 1) {
        throw new RuntimeException("No configuration file specified");
    }
    LOGGER.debug(String.format("Loading configuration from file; file=%s", args[0]));

    final File configurationFile = new File(args[0]);
    final Configurator<TsdAggregator, TsdAggregatorConfiguration> configurator = new Configurator<>(
            TsdAggregator.class, TsdAggregatorConfiguration.class);
    final ObjectMapper objectMapper = TsdAggregatorConfiguration.createObjectMapper();
    final DynamicConfiguration configuration = new DynamicConfiguration.Builder().setObjectMapper(objectMapper)
            .addSourceBuilder(
                    new JsonNodeFileSource.Builder().setObjectMapper(objectMapper).setFile(configurationFile))
            .addTrigger(new FileTrigger.Builder().setFile(configurationFile).build()).addListener(configurator)
            .build();

    configuration.launch();

    final AtomicBoolean isRunning = new AtomicBoolean(true);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            LOGGER.info("Stopping tsd-aggregator");
            configuration.shutdown();
            configurator.shutdown();
            isRunning.set(false);
        }
    }));

    while (isRunning.get()) {
        try {
            Thread.sleep(30000);
        } catch (final InterruptedException e) {
            break;
        }
    }

    LOGGER.info("Exiting tsd-aggregator");
}

From source file:misc.TablePrintDemo2.java

/**
 * Start the application.//w w w. j  a  v  a2s.  com
 */
public static void main(final String[] args) {
    /* Schedule for the GUI to be created and shown on the EDT */
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            /* Don't want bold fonts if we end up using metal */
            UIManager.put("swing.boldMetal", false);
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
            }
            new TablePrintDemo2().setVisible(true);
        }
    });
}