List of usage examples for java.lang Thread start
public synchronized void start()
From source file:io.seldon.importer.articles.FileItemAttributesImporter.java
/** * @param args// www. ja va 2 s . c o m * @throws InterruptedException * @throws FileNotFoundException */ public static void main(String[] args) throws InterruptedException, FileNotFoundException { FailFast failFast = new FailFast(Thread.currentThread()); { // Fail Fast thread Thread fail_fast_thread = new Thread(failFast); fail_fast_thread.setName("fail_fast_thread"); fail_fast_thread.start(); } try { Args.parse(FileItemAttributesImporter.class, args); DefaultApiClient client = new DefaultApiClient(apiUrl, consumerKey, consumerSecret, API_TIMEOUT); FileItemAttributesImporter fixer = new FileItemAttributesImporter(client); fixer.setFailFast(failFast); fixer.run(); } catch (IllegalArgumentException e) { e.printStackTrace(); Args.usage(FileItemAttributesImporter.class); } }
From source file:io.s4.zeno.SiteTest.java
public static void main(String[] arg) throws JSONException, KeeperException, IOException, InterruptedException { PropertyConfigurator.configure("log4j.properties"); String name = arg[0];/* w ww. j av a2s. c om*/ String zkaddr = arg[1]; String zkbase = arg[2]; String specStr = arg[3]; ConfigMap spec = new JSONConfigMap(specStr); ZooKeeper zk = new ZooKeeper(zkaddr, 3000, zkhandler); zookeeper = new ZooKeeperHelper(zk, 5, 5000); zkpath = new ZKPaths(zkbase); ZooKeeperInfo zkinfo = new ZooKeeperInfo(); zkinfo.zookeeper = zookeeper; zkinfo.zkpath = zkpath; zkinfo.taskHolder = new NonblockingLockset(zookeeper, zkpath.taskBase); zkinfo.partsHolder = new NonblockingLockset(zookeeper, zkpath.partsBase); zkinfo.standbySequence = new DistributedSequence(zookeeper, zkpath.standbyBase); final Site site = new Site(name, spec); ZKCluster cluster = new ZKCluster(zookeeper, zkpath); ZKJobList jobList = new ZKJobList(site, zkinfo); ZKPartList partList = new ZKPartList(site, zkinfo); SiteInitializer init = new SiteInitializer(); site.setCluster(cluster); site.setJobList(jobList); site.setPartList(partList); site.setInitializer(init); class ZenoThreadGroup extends ThreadGroup { public ZenoThreadGroup() { super("ZenoThreadGroup"); } public void uncaughtException(Thread t, Throwable e) { System.out.println("ZENOTHREADGROUP CAUGHT AND EXCEPTION FROM THREAD " + t + ". SO EXITING. DETAILS:" + e + "\nCAUSED BY: " + e.getCause() + "\n"); e.printStackTrace(); System.exit(1); } } Thread t = new Thread(new ZenoThreadGroup(), new Runnable() { public void run() { site.start(); } }, "zenorunthread"); t.start(); System.out.println(); t.join(); }
From source file:com.cloudera.beeswax.Server.java
public static void main(String[] args) throws TTransportException, MetaException, ParseException { parseArgs(args);//from w w w .ja v a 2 s. com createDirectoriesAsNecessary(); // Start metastore if specified if (mport != -1) { LOG.info("Starting metastore at port " + mport); Thread t = new Thread(new Runnable() { @Override public void run() { try { serveMeta(mport); } catch (TTransportException e) { e.printStackTrace(); } catch (MetaException e) { e.printStackTrace(); } } }, "MetaServerThread"); t.setDaemon(true); t.start(); } // Serve beeswax out of the main thread. LOG.info("Starting beeswaxd at port " + bport); serveBeeswax(bport); }
From source file:srvclientmonitor.frmMain.java
/** * @param args the command line arguments *//*from www . ja v a 2 s .com*/ 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(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(frmMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(() -> { frmMain _frmMain = new frmMain(); //Setea Color del Frame _frmMain.getContentPane().setBackground(Color.BLACK); _frmMain.setLocationRelativeTo(null); _frmMain.setTitle("Servicio de Ejecucin de Procesos - Log OUT: (Ingrese Login para activar)"); _frmMain.setVisible(true); //Setea color del Menu _frmMain.jMenuBar1.setBackground(Color.BLACK); _frmMain.jMenuBar1.setForeground(Color.WHITE); //Setea Color del Panel Principal _frmMain.pnlMain.setBackground(Color.BLACK); _frmMain.pnlMonMain.setBackground(Color.BLACK); _frmMain.pnlStatMon.setBackground(Color.black); _frmMain.pnlStatMon1.setBackground(Color.black); _frmMain.pnlStatMon2.setBackground(Color.black); _frmMain.pnlStatMon3.setBackground(Color.black); //Inicializa Componentes del Panel Principal _frmMain.lblMon.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_SPHERE_OFF_STATUS())); _frmMain.lblMon1.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_SPHERE_OFF_STATUS())); _frmMain.lblMon2.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_SPHERE_OFF_STATUS())); _frmMain.lblMon3.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_SPHERE_OFF_STATUS())); _frmMain.lblTime.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_TIME_STATUS())); _frmMain.lblTime1.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_TIME_STATUS())); _frmMain.lblActive1.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_TIME_STATUS())); _frmMain.lblActive2.setIcon(new ImageIcon(gDatos.getDIR_ICON_BASE() + gDatos.getICO_TIME_STATUS())); //Asocia a variables Globales gDatos.setLblMonDesc(_frmMain.lblMon); //Habilita Time Hour Thread _thTime = new thTime(_frmMain.lblTimeNow); _thTime.start(); }); }
From source file:com.sshtools.j2ssh.agent.SshAgentSocketListener.java
/** * The main entry point for the application. This method currently accepts * the -start parameter which will look for the sshtools.agent system * property. To configure the agent and to get a valid location call with * -configure, set the system sshtools.home system property and start. * * @param args the programs arguments/*w ww. j av a 2s . c o m*/ */ public static void main(String[] args) { if (args.length > 0) { if (args[0].equals("-start")) { Thread thread = new Thread(new Runnable() { public void run() { try { SshAgentSocketListener agent = new SshAgentSocketListener( System.getProperty("sshtools.agent"), new KeyStore()); agent.start(); } catch (Exception ex) { ex.printStackTrace(); } } }); thread.start(); } if (args[0].equals("-configure")) { System.out.println("SET SSHTOOLS_AGENT=localhost:" + String.valueOf(configureNewLocation())); } } }
From source file:com.minoritycode.Application.java
public static void main(String[] args) { System.out.println("Trello Backup Application"); File configFile = new File(workingDir + "\\config.properties"); InputStream input = null;//from w ww. j a v a 2 s.c om try { input = new FileInputStream(configFile); config.load(input); input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // String workingDir = System.getProperty("user.dir"); manualOperation = Boolean.parseBoolean(config.getProperty("manualOperation")); logger.startErrorLogger(); setBackupDir(); try { report.put("backupDate", backupDate); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } lock = new ReentrantLock(); lockErrorRep = new ReentrantLock(); lockErrorLog = new ReentrantLock(); Application.key = config.getProperty("trellokey"); Application.token = config.getProperty("trellotoken"); boolean useProxy = Boolean.parseBoolean(config.getProperty("useProxy")); boolean proxySet = true; if (useProxy) { proxySet = setProxy(); } // GUI swingContainerDemo = new GUI(); // swingContainerDemo.showJPanelDemo(); if (proxySet) { Credentials credentials = new Credentials(); if (Application.key.isEmpty()) { Application.key = credentials.getKey(); } else { Application.key = config.getProperty("trellokey"); } if (token.isEmpty()) { Application.token = credentials.getToken(); } else { Application.token = config.getProperty("trellotoken"); } BoardDownloader downloader = new BoardDownloader(); downloader.downloadMyBoard(url); boards = downloader.downloadOrgBoard(url); if (boards != null) { try { report.put("boardNum", boards.size()); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } Integer numberOfThreads = Integer.parseInt(config.getProperty("numberOfThreads")); if (numberOfThreads == null) { logger.logLine("error number of threads not set in config file"); if (manualOperation) { String message = "How many threads do you want to use (10) is average"; numberOfThreads = Integer.parseInt(Credentials.getInput(message)); Credentials.saveProperty("numberOfThreads", numberOfThreads.toString()); } else { if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } System.exit(-1); } } ArrayList<Thread> threadList = new ArrayList<Thread>(); for (int i = 0; i < numberOfThreads; i++) { Thread thread = new Thread(new Application(), "BoardDownloadThread"); threadList.add(thread); thread.start(); } } else { //create empty report try { report.put("boardsNotDownloaded", "99999"); report.put("boardNum", 0); report.put("boardNumSuccessful", 0); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } logger.logger(report); } } else { //create empty report try { report.put("boardsNotDownloaded", "99999"); report.put("boardNum", 0); report.put("boardNumSuccessful", 0); } catch (JSONException e) { e.printStackTrace(); logger.logLine(e.getMessage()); } if (Boolean.parseBoolean(config.getProperty("useMailer"))) { Mailer mailer = new Mailer(); mailer.SendMail(); } } }
From source file:InvokeExample.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.add(good);/* ww w. j ava 2 s .c o m*/ p.add(bad); p.add(bad2); Container c = f.getContentPane(); c.setLayout(new BorderLayout()); c.add(p, BorderLayout.CENTER); c.add(resultLabel, BorderLayout.SOUTH); good.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { resultLabel.setText("Working . . ."); setEnabled(false); Thread worker = new Thread() { public void run() { try { Thread.sleep(5000); } catch (InterruptedException ex) { } SwingUtilities.invokeLater(new Runnable() { public void run() { resultLabel.setText("Ready"); setEnabled(true); } }); } }; worker.start(); } }); bad.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { resultLabel.setText("Working . . ."); setEnabled(false); try { Thread.sleep(5000); } catch (InterruptedException ex) { } resultLabel.setText("Ready"); setEnabled(true); } }); bad2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { resultLabel.setText("Working . . . "); setEnabled(false); SwingUtilities.invokeLater(new Runnable() { public void run() { try { Thread.sleep(5000); // Dispatch thread is starving! } catch (InterruptedException ex) { } resultLabel.setText("Ready"); setEnabled(true); } }); } }); f.setSize(300, 100); f.setVisible(true); }
From source file:edu.uci.ics.asterix.transaction.management.service.locking.LockManagerDeterministicUnitTest.java
public static void main(String args[]) throws ACIDException, IOException, AsterixException { //prepare configuration file File cwd = new File(System.getProperty("user.dir")); File asterixdbDir = cwd.getParentFile(); File srcFile = new File(asterixdbDir.getAbsoluteFile(), "asterix-app/src/main/resources/asterix-build-configuration.xml"); File destFile = new File(cwd, "target/classes/asterix-configuration.xml"); FileUtils.copyFile(srcFile, destFile); //initialize controller thread String requestFileName = new String( "src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/LockRequestFile"); Thread t = new Thread(new LockRequestController(requestFileName)); t.start(); }
From source file:org.eclipse.swt.snippets.Snippet7.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 16, 16); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(image.getBounds()); gc.dispose();//from w ww . j ava 2 s . c om final Shell shell = new Shell(display); shell.setText("Lazy Table"); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setSize(200, 200); Thread thread = new Thread() { @Override public void run() { for (int i = 0; i < 20000; i++) { if (table.isDisposed()) return; final int[] index = new int[] { i }; display.syncExec(() -> { if (table.isDisposed()) return; TableItem item = new TableItem(table, SWT.NONE); item.setText("Table Item " + index[0]); item.setImage(image); }); } } }; thread.start(); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:com.yulore.demo.NHttpClient.java
public static void main(String[] args) throws Exception { // Create HTTP protocol processing chain HttpProcessor httpproc = HttpProcessorBuilder.create() // Use standard client-side protocol interceptors .add(new RequestContent()).add(new RequestTargetHost()).add(new RequestConnControl()) .add(new RequestUserAgent("Test/1.1")).add(new RequestExpectContinue(true)).build(); // Create client-side HTTP protocol handler HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor(); // Create client-side I/O event dispatch final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, ConnectionConfig.DEFAULT);/*from w w w . ja v a2s . c o m*/ // Create client-side I/O reactor final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(); // Create HTTP connection pool BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT); // Limit total number of connections to just two pool.setDefaultMaxPerRoute(2); pool.setMaxTotal(2); // Run the I/O reactor in a separate thread Thread t = new Thread(new Runnable() { public void run() { try { // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); } }); // Start the client thread t.start(); // Create HTTP requester HttpAsyncRequester requester = new HttpAsyncRequester(httpproc); // Execute HTTP GETs to the following hosts and HttpHost[] targets = new HttpHost[] { new HttpHost("www.apache.org", 80, "http"), new HttpHost("www.verisign.com", 443, "https"), new HttpHost("www.google.com", 80, "http") }; final CountDownLatch latch = new CountDownLatch(targets.length); for (final HttpHost target : targets) { BasicHttpRequest request = new BasicHttpRequest("GET", "/"); HttpCoreContext coreContext = HttpCoreContext.create(); requester.execute(new BasicAsyncRequestProducer(target, request), new BasicAsyncResponseConsumer(), pool, coreContext, // Handle HTTP response from a callback new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { latch.countDown(); System.out.println(target + "->" + response.getStatusLine()); } public void failed(final Exception ex) { latch.countDown(); System.out.println(target + "->" + ex); } public void cancelled() { latch.countDown(); System.out.println(target + " cancelled"); } }); } latch.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }