List of usage examples for java.util.concurrent ExecutorService execute
void execute(Runnable command);
From source file:DIA_Umpire_To_Skyline.DIA_Umpire_To_Skyline.java
/** * @param args the command line arguments *//* w w w . j av a 2 s.c o m*/ public static void main(String[] args) throws FileNotFoundException, IOException, Exception { System.out.println( "================================================================================================="); System.out.println("DIA-Umpire_To_Skyline (version: " + UmpireInfo.GetInstance().Version + ")"); if (args.length < 1) { System.out.println( "command format error, it should be like: java -jar -Xmx20G DIA_Umpire_To_Skyline.jar Path NoThreads"); System.out.println("command : java -jar -Xmx20G DIA_Umpire_To_Skyline.jar Path [Option]\n"); System.out.println("\nOptions"); System.out.println("\t-t\tNo. of threads, Ex: -t4 (using four threads, default value)"); System.out.println( "\t-cP\tPath of msconvert.exe for mzXML conversion, Ex: -cP (using four threads, default value)"); return; } try { ConsoleLogger.SetConsoleLogger(Level.DEBUG); ConsoleLogger.SetFileLogger(Level.DEBUG, FilenameUtils.getFullPath(args[0]) + "diaumpire_to_skyline.log"); } catch (Exception e) { System.out.println("Logger initialization failed"); } Logger.getRootLogger().info("Path:" + args[0]); String msconvertpath = "C:/inetpub/tpp-bin/msconvert"; String WorkFolder = args[0]; int NoCPUs = 4; for (int i = 1; i < args.length; i++) { if (args[i].startsWith("-")) { if (args[i].startsWith("-cP")) { msconvertpath = args[i].substring(3); Logger.getRootLogger().info("MSConvert path: " + msconvertpath); } if (args[i].startsWith("-t")) { NoCPUs = Integer.parseInt(args[i].substring(2)); Logger.getRootLogger().info("No. of threads: " + NoCPUs); } } } HashMap<String, File> AssignFiles = new HashMap<>(); try { File folder = new File(WorkFolder); if (!folder.exists()) { Logger.getRootLogger().info("Path: " + folder.getAbsolutePath() + " cannot be found."); } for (final File fileEntry : folder.listFiles()) { if (fileEntry.isFile() && fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry); } if (fileEntry.isDirectory()) { for (final File fileEntry2 : fileEntry.listFiles()) { if (fileEntry2.isFile() && fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2); } } } } Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size()); for (File fileEntry : AssignFiles.values()) { Logger.getRootLogger().info(fileEntry.getAbsolutePath()); } ExecutorService executorPool = null; executorPool = Executors.newFixedThreadPool(3); for (File fileEntry : AssignFiles.values()) { String mzXMLFile = fileEntry.getAbsolutePath(); FileThread thread = new FileThread(mzXMLFile, NoCPUs, msconvertpath); executorPool.execute(thread); } executorPool.shutdown(); try { executorPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { Logger.getRootLogger().info("interrupted.."); } } catch (Exception e) { Logger.getRootLogger().error(e.getMessage()); throw e; } Logger.getRootLogger().info("Job done"); Logger.getRootLogger().info( "================================================================================================="); }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer561.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer561Runnable(Integer.toString(i)); executor.execute(worker); }/*from w w w. ja va2 s. com*/ }
From source file:org.mongodb.tse.tests.RunQueryThreadPool.java
public static void main(String[] args) { Option help = Option.builder("help").argName("help").desc("get help").build(); Option ouri = Option.builder("uri").argName("uri").desc("mongodb uri, required").hasArg().type(String.class) .build();//from w ww. j a v a 2 s . c om Option odatabase = Option.builder("database").argName("database") .desc("mongodb database, default productpersistdb").hasArg().type(String.class).build(); Option ocollection = Option.builder("collection").argName("collection") .desc("mongodb collection, default product").hasArg().type(String.class).build(); Option osleep = Option.builder("sleep").argName("sleep").desc("sleep between runs, default 10 seconds") .hasArg().type(Integer.class).build(); Option othreads = Option.builder("threads").argName("threads").desc("number of threads to run, default 5") .hasArg().type(Integer.class).build(); Option readPreference = Option.builder("readPreference").argName("readPreference") .desc("read preference, default is secondaryPreferred").hasArg().type(String.class).build(); Option oids = Option.builder("ids").argName("ids").desc("list of comma separated ids").hasArg() .type(String.class).build(); Option oidFile = Option.builder("idFile").argName("idFile").desc("file containing ids per line").hasArg() .type(String.class).build(); Option oincludeslow = Option.builder("includeslow").argName("includeslow") .desc("run slow query that will pause 1 second for every document in collection").build(); Option oincreasethreads = Option.builder("increasethreads").argName("increasethreads") .desc("increase thread count every second until this number").hasArg().type(Integer.class).build(); Options options = new Options(); options.addOption(help); options.addOption(ouri); options.addOption(odatabase); options.addOption(ocollection); options.addOption(osleep); options.addOption(othreads); options.addOption(readPreference); options.addOption(oids); options.addOption(oidFile); options.addOption(oincludeslow); options.addOption(oincreasethreads); CommandLineParser parser = new DefaultParser(); CommandLine cline = null; try { // parse the command line arguments cline = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); } if (args.length == 0 || cline.hasOption("help") || !cline.hasOption("uri")) { printHelp(options); } final String[] ids = parseIdFile(cline); String uriParameter = cline.getOptionValue("uri"); String databaseParameter = cline.getOptionValue("database", "productpersistdb"); String collectionParameter = cline.getOptionValue("collection", "product"); System.out.println("Using database: " + databaseParameter + " and collection: " + collectionParameter); MongoClientURI uri = new MongoClientURI(uriParameter); MongoClient mongoClient = new MongoClient(uri); MongoDatabase database = mongoClient.getDatabase(databaseParameter); final MongoCollection<Document> collection = getCollection(cline, database, collectionParameter); long tsleep = 10000; if (cline.hasOption("sleep")) tsleep = Integer.parseInt(cline.getOptionValue("sleep")) * 1000; final long sleep = tsleep; int threads = 5; if (cline.hasOption("threads")) threads = Integer.parseInt(cline.getOptionValue("threads")); int max = ids.length; boolean includeslow = cline.hasOption("includeslow"); ExecutorService pool = Executors.newCachedThreadPool(); for (int i = 0; i < threads; i++) { pool.execute(new Runnable() { public void run() { int count = 0; for (;;) { String id = ids[(count % max)]; Document doc = null; RawBsonDocument raw = null; Date date = new Date(); long end = 0L; long start = System.nanoTime(); try { if (includeslow //&& ( count % 2 ) == 0 ) { FindIterable<Document> fit = collection .find(where("function() { " + "var d = new Date((new Date()).getTime() + 1*1000); " + "while ( d > (new Date())) { }; " + "return true;" + "}")) .limit(100); int dcount = 0; for (Document d : fit) { dcount++; } System.out.println( String.format("%s - slow query, count:%s, start: %s, elasped: %s ns", Thread.currentThread().getName(), dcount, date, (end - start))); } else { doc = collection .find(and(eq("_id", id), where("function() { " + "var d = new Date((new Date()).getTime() + 1*1000); " + "while ( d > (new Date())) { }; " + "return true;" + "}"))) .first(); end = System.nanoTime(); if (doc == null) System.out.println("Could not find " + id); System.out.println(String.format("%s - id: %s, start: %s, elasped: %s ns", Thread.currentThread().getName(), id, date, (end - start))); } } catch (Exception e) { System.out.println("Got an exception: " + e.getMessage()); e.printStackTrace(); try { Thread.sleep(1000); } catch (InterruptedException e2) { } } //try { Thread.sleep(sleep); } catch ( InterruptedException e ) {} count++; } } }); } if (cline.hasOption("increasethreads")) { int increaseThreads = Integer.parseInt(cline.getOptionValue("increasethreads")); for (int i = threads; i < increaseThreads; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { } pool.execute(new Runnable() { public void run() { int count = 0; for (;;) { String id = ids[(count % max)]; Document doc = null; RawBsonDocument raw = null; Date date = new Date(); long end = 0L; long start = System.nanoTime(); try { if (includeslow //&& ( count % 2 == 0 ) ) { FindIterable<Document> fit = collection .find(where("function() { " + "var d = new Date((new Date()).getTime() + 1*1000); " + "while ( d > (new Date())) { }; " + "return true;" + "}")) .limit(100); int dcount = 0; for (Document d : fit) { dcount++; } System.out.println( String.format("%s - slow query, count:%s, start: %s, elasped: %s ns", Thread.currentThread().getName(), dcount, date, (end - start))); } else { doc = collection .find(and(eq("_id", id), where("function() { " + "var d = new Date((new Date()).getTime() + 1*1000); " + "while ( d > (new Date())) { }; " + "return true;" + "}"))) .first(); end = System.nanoTime(); if (doc == null) System.out.println("Could not find " + id); System.out.println(String.format("%s - id: %s, start: %s, elasped: %s ns", Thread.currentThread().getName(), id, date, (end - start))); } } catch (Exception e) { System.out.println("Got an exception: " + e.getMessage()); e.printStackTrace(); try { Thread.sleep(1000); } catch (InterruptedException e2) { } } //try { Thread.sleep(sleep); } catch ( InterruptedException e ) {} count++; } } }); } } }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer555.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer555Runnable(Integer.toString(i)); executor.execute(worker); }/*w ww . j a v a 2 s . c om*/ }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer559.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer559Runnable(Integer.toString(i)); executor.execute(worker); }//from w ww . j a v a 2s . c o m }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer556.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer556Runnable(Integer.toString(i)); executor.execute(worker); }// w w w. ja v a 2 s. co m }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer558.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer558Runnable(Integer.toString(i)); executor.execute(worker); }// w w w . ja va 2 s .c om }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer562.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer562Runnable(Integer.toString(i)); executor.execute(worker); }/* w ww. ja v a 2 s . com*/ }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer563.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer563Runnable(Integer.toString(i)); executor.execute(worker); }/* www . j a v a2s.c o m*/ }
From source file:com.netcore.hsmart.smsconsumers.SmsConsumer564.java
public static void main(String args[]) throws Exception { ExecutorService executor = Executors.newCachedThreadPool(); for (int i = 1; i <= COUNTERS; i++) { Runnable worker = new SmsConsumer564Runnable(Integer.toString(i)); executor.execute(worker); }// w ww .j a va 2 s . com }