public static void main(String[] args) throws TalesException { try { Options options = new Options(); options.addOption("template", true, "template class path"); options.addOption("threads", true, "number of templates"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String templatePath = cmd.getOptionValue("template"); int threads = Integer.parseInt(cmd.getOptionValue("threads")); // when app is killed Runtime.getRuntime() .addShutdownHook( new Thread() { public void run() { if (taskWorker != null) { taskWorker.stop(); } Logger.log(new Throwable(), "---> bye..."); } }); // monitors the app performance AppMonitor.init(); // reflection / new template TemplateInterface template = (TemplateInterface) Class.forName(templatePath).newInstance(); // connection Connection connection = new Connection(); connection.setConnectionsNumber(threads); // scraper config ScraperConfig scraperConfig = new ScraperConfig(); scraperConfig.setScraperName("LoopScraper"); scraperConfig.setTemplate(template); scraperConfig.setConnection(connection); // scraper LoopScraper.init(scraperConfig); // stop AppMonitor.stop(); System.exit(0); } catch (Exception e) { AppMonitor.stop(); System.exit(0); throw new TalesException(new Throwable(), e); } }