List of usage examples for java.lang Runnable Runnable
Runnable
From source file:com.cfelde.aws.ddb.management.TableThroughput.java
public static void main(String... args) { loadPartitionState();/*from w ww.j a va2 s .co m*/ // TODO: All these parameters should be loaded from a config file! String accessKey = "YOUR ACCESS KEY"; String secretKey = "YOUR SECRET KEY"; AmazonCloudWatch client = new AmazonCloudWatchClient(new BasicAWSCredentials(accessKey, secretKey)); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new BasicAWSCredentials(accessKey, secretKey)); client.setEndpoint("https://monitoring.eu-west-1.amazonaws.com"); ddb.setEndpoint("https://dynamodb.eu-west-1.amazonaws.com"); // Do one per table you want to manage initTableThroughput(client, ddb, "table1", 2, 100, 2, 100); initTableThroughput(client, ddb, "table2", 2, 100, 2, 100); executor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { storePartitionState(); } }, 16, 61, TimeUnit.MINUTES); }
From source file:com.adobe.aem.demomachine.gui.AemDemo.java
public static void main(String[] args) { String demoMachineRootFolder = null; // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Path to Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try {/* w ww. j a va 2s .c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { demoMachineRootFolder = cmd.getOptionValue("f"); } } catch (ParseException ex) { logger.error(ex.getMessage()); } // Let's grab the version number for the core Maven file String mavenFilePath = (demoMachineRootFolder != null ? demoMachineRootFolder : System.getProperty("user.dir")) + File.separator + "java" + File.separator + "core" + File.separator + "pom.xml"; File mavenFile = new File(mavenFilePath); if (mavenFile.exists() && !mavenFile.isDirectory()) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document; document = builder.parse(mavenFile); NodeList list = document.getElementsByTagName("version"); if (list != null && list.getLength() > 0) { aemDemoMachineVersion = list.item(0).getFirstChild().getNodeValue(); } } catch (Exception e) { logger.error("Can't parse Maven pom.xml file"); } } // Let's check if we have a valid build.xml file to work with... String buildFilePath = (demoMachineRootFolder != null ? demoMachineRootFolder : System.getProperty("user.dir")) + File.separator + "build.xml"; logger.debug("Trying to load build file from " + buildFilePath); buildFile = new File(buildFilePath); if (buildFile.exists() && !buildFile.isDirectory()) { // Launching the main window EventQueue.invokeLater(new Runnable() { public void run() { try { UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("Arial", Font.BOLD, 14)); AemDemo window = new AemDemo(); window.frameMain.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } else { logger.error("No valid build.xml file to work with"); System.exit(-1); } }
From source file:gui.ResultadoDistFreq.java
/** * @param args the command line arguments */// w w w. j a va 2 s . c o m public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ResultadoDistFreq.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ResultadoDistFreq.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ResultadoDistFreq.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ResultadoDistFreq.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ResultadoDistFreq().setVisible(true); } }); }
From source file:learn.CelsiusConverterGUI.java
/** * @param args the command line arguments *///from w w w.j av a 2 s . c om public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new CelsiusConverterGUI().setVisible(true); } }); }
From source file:de.stefanwndelmann.zy1270logger.Test.TestJFreeChart.java
/** * @param args the command line arguments *//*from w w w . ja va2 s.c o m*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(TestJFreeChart.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(TestJFreeChart.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(TestJFreeChart.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(TestJFreeChart.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TestJFreeChart().setVisible(true); } }); }
From source file:de.codesourcery.eve.skills.ui.Main.java
public static void main(String[] args) throws Exception { setLookAndFeel();/*from w w w. jav a 2 s . c om*/ SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { SpringUtil.getInstance().getMain().startUp(); } catch (Exception e) { throw new RuntimeException(e); } } }); }
From source file:pe.egcc.app.demo.Demo02.java
/** * @param args the command line arguments */// w ww. j a va2s . c o m public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Demo02.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Demo02.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Demo02.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Demo02.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Demo02().setVisible(true); } }); }
From source file:net.sf.mpaxs.test.ImpaxsExecution.java
/** * * @param args/*from w w w. java 2 s . c o m*/ */ public static void main(String[] args) { Options options = new Options(); Option[] optionArray = new Option[] { OptionBuilder.withArgName("nhosts").hasArg() .withDescription("Number of hosts for parallel processing").create("n"), OptionBuilder.withArgName("mjobs").hasArg().withDescription("Number of jobs to run in parallel") .create("m"), OptionBuilder.withArgName("runmode").hasArg() .withDescription("The mode in which to operate: one of <ALL,LOCAL,DISTRIBUTED>") .create("r"), // OptionBuilder.withArgName("gui"). // withDescription("Create gui for distributed execution").create("g") }; for (Option opt : optionArray) { options.addOption(opt); } if (args.length == 0) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(StartUp.class.getCanonicalName(), options, true); System.exit(1); } GnuParser gp = new GnuParser(); int nhosts = 1; int mjobs = 10; boolean gui = false; Mode mode = Mode.ALL; try { CommandLine cl = gp.parse(options, args); if (cl.hasOption("n")) { nhosts = Integer.parseInt(cl.getOptionValue("n")); } if (cl.hasOption("m")) { mjobs = Integer.parseInt(cl.getOptionValue("m")); } if (cl.hasOption("r")) { mode = Mode.valueOf(cl.getOptionValue("r")); } // if (cl.hasOption("g")) { // gui = true; // } } catch (Exception ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); HelpFormatter hf = new HelpFormatter(); hf.printHelp(StartUp.class.getCanonicalName(), options, true); System.exit(1); } String version; try { version = net.sf.mpaxs.api.Version.getVersion(); System.out.println("Running mpaxs " + version); File computeHostJarLocation = new File(System.getProperty("user.dir"), "mpaxs.jar"); if (!computeHostJarLocation.exists() || !computeHostJarLocation.isFile()) { throw new IOException("Could not locate mpaxs.jar in " + System.getProperty("user.dir")); } final PropertiesConfiguration cfg = new PropertiesConfiguration(); //set default execution type cfg.setProperty(ConfigurationKeys.KEY_EXECUTION_MODE, ExecutionType.DRMAA); //set location of compute host jar cfg.setProperty(ConfigurationKeys.KEY_PATH_TO_COMPUTEHOST_JAR, computeHostJarLocation); //do not exit to console when master server shuts down cfg.setProperty(ConfigurationKeys.KEY_MASTER_SERVER_EXIT_ON_SHUTDOWN, false); //limit the number of used compute hosts cfg.setProperty(ConfigurationKeys.KEY_MAX_NUMBER_OF_CHOSTS, nhosts); cfg.setProperty(ConfigurationKeys.KEY_NATIVE_SPEC, ""); cfg.setProperty(ConfigurationKeys.KEY_GUI_MODE, gui); cfg.setProperty(ConfigurationKeys.KEY_SILENT_MODE, true); cfg.setProperty(ConfigurationKeys.KEY_SCHEDULE_WAIT_TIME, "500"); final int maxJobs = mjobs; final int maxThreads = nhosts; final Mode runMode = mode; printMessage("Run mode: " + runMode); Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { if (runMode == Mode.ALL || runMode == Mode.LOCAL) { printMessage("Running Within VM Execution"); /* * LOCAL within VM execution */ WithinVmExecution lhe = new WithinVmExecution(maxJobs, maxThreads); try { Logger.getLogger(ImpaxsExecution.class.getName()).log(Level.INFO, "Sum is: " + lhe.call()); } catch (Exception ex) { Logger.getLogger(ImpaxsExecution.class.getName()).log(Level.SEVERE, null, ex); } } if (runMode == Mode.ALL || runMode == Mode.DISTRIBUTED) { printMessage("Running Distributed Host RMI Execution"); /* * Grid Engine (DRMAA API) or local host distributed RMI execution */ DistributedRmiExecution de = new DistributedRmiExecution(cfg, maxJobs); try { Logger.getLogger(ImpaxsExecution.class.getName()).log(Level.INFO, "Sum is: " + de.call()); } catch (Exception ex) { Logger.getLogger(ImpaxsExecution.class.getName()).log(Level.SEVERE, null, ex); } } System.exit(0); } }); } catch (IOException ex) { Logger.getLogger(ImpaxsExecution.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.albraga.namus.OverlaypdfUI.java
/** * @param args the command line arguments *//*from w ww. j ava 2 s . co m*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(OverlaypdfUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(OverlaypdfUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(OverlaypdfUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(OverlaypdfUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new OverlaypdfUI().setVisible(true); } }); }
From source file:com.wouterbreukink.onedrive.Main.java
public static void main(String[] args) throws Exception { // Parse command line args try {//from w ww . ja va 2 s .c om CommandLineOpts.initialise(args); } catch (ParseException ex) { log.error("Unable to parse command line arguments - " + ex.getMessage()); CommandLineOpts.printHelp(); return; } if (getCommandLineOpts().help()) { CommandLineOpts.printHelp(); return; } if (getCommandLineOpts().version()) { String version = getCommandLineOpts().getClass().getPackage().getImplementationVersion(); log.info("onedrive-java-client version " + (version != null ? version : "DEVELOPMENT")); return; } // Initialise a log file (if set) if (getCommandLineOpts().getLogFile() != null) { String logFileName = LogUtils.addFileLogger(getCommandLineOpts().getLogFile()); log.info(String.format("Writing log output to %s", logFileName)); } if (getCommandLineOpts().isAuthorise()) { AuthorisationProvider.FACTORY.printAuthInstructions(); return; } if (getCommandLineOpts().getLocalPath() == null || getCommandLineOpts().getRemotePath() == null || getCommandLineOpts().getDirection() == null) { log.error("Must specify --local, --remote and --direction"); CommandLineOpts.printHelp(); return; } // Initialise the OneDrive authorisation AuthorisationProvider authoriser; try { authoriser = AuthorisationProvider.FACTORY.create(getCommandLineOpts().getKeyFile()); authoriser.getAccessToken(); } catch (OneDriveAPIException ex) { log.error("Unable to authorise client: " + ex.getMessage()); log.error("Re-run the application with --authorise"); return; } // Initialise the providers OneDriveProvider api; FileSystemProvider fileSystem; if (getCommandLineOpts().isDryRun()) { log.warn("This is a dry run - no changes will be made"); api = OneDriveProvider.FACTORY.readOnlyApi(authoriser); fileSystem = FileSystemProvider.FACTORY.readOnlyProvider(); } else { api = OneDriveProvider.FACTORY.readWriteApi(authoriser); fileSystem = FileSystemProvider.FACTORY.readWriteProvider(); } // Report on progress TaskReporter reporter = new TaskReporter(); // Get the primary drive Drive primary = api.getDefaultDrive(); // Report quotas log.info(String.format("Using drive with id '%s' (%s). Usage %s of %s (%.2f%%)", primary.getId(), primary.getDriveType(), readableFileSize(primary.getQuota().getUsed()), readableFileSize(primary.getQuota().getTotal()), ((double) primary.getQuota().getUsed() / primary.getQuota().getTotal()) * 100)); // Check the given root folder OneDriveItem rootFolder = api.getPath(getCommandLineOpts().getRemotePath()); if (!rootFolder.isDirectory()) { log.error(String.format("Specified root '%s' is not a folder", rootFolder.getFullName())); return; } File localRoot = new File(getCommandLineOpts().getLocalPath()); log.info(String.format("Local folder '%s'", localRoot.getAbsolutePath())); log.info(String.format("Remote folder '<onedrive>%s'", rootFolder.getFullName())); // Start synchronisation operation at the root final TaskQueue queue = new TaskQueue(); queue.add(new CheckTask(new Task.TaskOptions(queue, api, fileSystem, reporter), rootFolder, localRoot)); // Get a bunch of threads going ExecutorService executorService = Executors.newFixedThreadPool(getCommandLineOpts().getThreads()); for (int i = 0; i < getCommandLineOpts().getThreads(); i++) { executorService.submit(new Runnable() { @Override public void run() { try { //noinspection InfiniteLoopStatement while (true) { Task taskToRun = null; try { taskToRun = queue.take(); taskToRun.run(); } finally { if (taskToRun != null) { queue.done(taskToRun); } } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }); } queue.waitForCompletion(); log.info("Synchronisation complete"); reporter.report(); }