List of usage examples for java.lang Thread start
public synchronized void start()
From source file:TryThread.java
public static void main(String[] args) { Thread first = new TryThread("A ", "a ", 200L); Thread second = new TryThread("B ", "b ", 300L); Thread third = new TryThread("C ", "c ", 500L); System.out.println("Press Enter when you have had enough...\n"); first.start(); second.start();/* w w w .jav a 2s. co m*/ third.start(); try { System.in.read(); System.out.println("Enter pressed...\n"); } catch (IOException e) { System.out.println(e); } return; }
From source file:net.fender.crypto.CryptoUtil.java
/** * Verify thread safety of org.apache.commons.codec.binary.Base64. * /*from w w w . j a va2 s. c om*/ * @TODO Move this to JUnit test case. * @param args * @throws Exception */ public static void main(String[] args) throws Exception { byte[][] strings = new byte[10000][]; // generate a bunch of random "strings" for (int i = 0; i < strings.length; i++) { // generate a random "string" 32 - 64 bytes long byte[] bytes = new byte[random.nextInt(32) + 32]; random.nextBytes(bytes); strings[i] = bytes; } Runner runner = new Runner(strings); for (int i = 0; i < 100; i++) { Thread t = new Thread(runner); t.start(); } }
From source file:Main.java
public static void main(String[] args) { Thread t = new Thread(new MyThread()); t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { System.out.println(t + " throws exception: " + e); }//from w ww. j av a 2 s. c o m }); t.start(); }
From source file:MainClass.java
public static void main(String[] args) { Thread thread = new Thread(new MyThread()); thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { System.out.println(t + " threw exception: " + e); }//from ww w.j av a2s . c o m }); thread.start(); }
From source file:Main.java
public static void main(String[] args) { Thread t = new Thread(new MyThread()); t.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { System.out.println(t + " throws exception: " + e); }// w w w . ja v a 2 s.co m }); t.start(); }
From source file:webdriver.test.BasicHttpServer.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Please specify HTTP document root directory as "); System.err.println("a argument relative to the run directory."); Thread.sleep(10);//from w w w. ja va 2 s. c om System.exit(1); } Thread t = new RequestListenerThread(8001, args[0]); t.setDaemon(false); t.start(); }
From source file:ab.demo.MainEntry.java
public static void main(String args[]) { LoggingHandler.initConsoleLog();//from w ww .j a v a 2 s. com //args = new String[]{"-su"}; Options options = new Options(); options.addOption("s", "standalone", false, "runs the reinforcement learning agent in standalone mode"); options.addOption("p", "proxyPort", true, "the port which is to be used by the proxy"); options.addOption("h", "help", false, "displays this help"); options.addOption("n", "naiveAgent", false, "runs the naive agent in standalone mode"); options.addOption("c", "competition", false, "runs the naive agent in the server/client competition mode"); options.addOption("u", "updateDatabaseTables", false, "executes CREATE TABLE IF NOT EXIST commands"); options.addOption("l", "level", true, "if set the agent is playing only in this one level"); options.addOption("m", "manual", false, "runs the empirical threshold determination agent in standalone mode"); options.addOption("r", "real", false, "shows the recognized shapes in a new frame"); CommandLineParser parser = new DefaultParser(); CommandLine cmd; StandaloneAgent agent; Properties properties = new Properties(); InputStream configInputStream = null; try { Class.forName("org.sqlite.JDBC"); //parse configuration file configInputStream = new FileInputStream("config.properties"); properties.load(configInputStream); } catch (IOException exception) { exception.printStackTrace(); } catch (ClassNotFoundException exception) { exception.printStackTrace(); } finally { if (configInputStream != null) { try { configInputStream.close(); } catch (IOException exception) { exception.printStackTrace(); } } } String dbPath = properties.getProperty("db_path"); String dbUser = properties.getProperty("db_user"); String dbPass = properties.getProperty("db_pass"); DBI dbi = new DBI(dbPath, dbUser, dbPass); QValuesDAO qValuesDAO = dbi.open(QValuesDAO.class); GamesDAO gamesDAO = dbi.open(GamesDAO.class); MovesDAO movesDAO = dbi.open(MovesDAO.class); ProblemStatesDAO problemStatesDAO = dbi.open(ProblemStatesDAO.class); try { cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("help", options); return; } int proxyPort = 9000; if (cmd.hasOption("proxyPort")) { proxyPort = Integer.parseInt(cmd.getOptionValue("proxyPort")); logger.info("Set proxy port to " + proxyPort); } Proxy.setPort(proxyPort); LoggingHandler.initFileLog(); if (cmd.hasOption("standalone")) { agent = new ReinforcementLearningAgent(gamesDAO, movesDAO, problemStatesDAO, qValuesDAO); } else if (cmd.hasOption("naiveAgent")) { agent = new NaiveStandaloneAgent(); } else if (cmd.hasOption("manual")) { agent = new ManualGamePlayAgent(gamesDAO, movesDAO, problemStatesDAO); } else if (cmd.hasOption("competition")) { System.out.println("We haven't implemented a competition ready agent yet."); return; } else { System.out.println("Please specify which solving strategy we should be using."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("help", options); return; } if (cmd.hasOption("updateDatabaseTables")) { qValuesDAO.createTable(); gamesDAO.createTable(); movesDAO.createTable(); problemStatesDAO.createTable(); problemStatesDAO.createObjectsTable(); } if (cmd.hasOption("level")) { agent.setFixedLevel(Integer.parseInt(cmd.getOptionValue("level"))); } if (cmd.hasOption("real")) { ShowSeg.useRealshape = true; Thread thread = new Thread(new ShowSeg()); thread.start(); } } catch (UnrecognizedOptionException e) { System.out.println("Unrecognized commandline option: " + e.getOption()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("help", options); return; } catch (ParseException e) { System.out.println( "There was an error while parsing your command line input. Did you rechecked your syntax before running?"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("help", options); return; } agent.run(); }
From source file:com.samczsun.helios.bootloader.Bootloader.java
public static void main(String[] args) { try {//from ww w . j a v a2s . c o m if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs()) throw new RuntimeException("Could not create data directory"); if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs()) throw new RuntimeException("Could not create addons directory"); if (!Constants.SETTINGS_FILE.exists() && !Constants.SETTINGS_FILE.createNewFile()) throw new RuntimeException("Could not create settings file"); if (Constants.DATA_DIR.isFile()) throw new RuntimeException("Data directory is file"); if (Constants.ADDONS_DIR.isFile()) throw new RuntimeException("Addons directory is file"); if (Constants.SETTINGS_FILE.isDirectory()) throw new RuntimeException("Settings file is directory"); loadSWTLibrary(); DisplayPumper displayPumper = new DisplayPumper(); if (System.getProperty("os.name").toLowerCase().contains("mac")) { System.out.println("Attemting to force main thread"); Executor executor; try { Class<?> dispatchClass = Class.forName("com.apple.concurrent.Dispatch"); Object dispatchInstance = dispatchClass.getMethod("getInstance").invoke(null); executor = (Executor) dispatchClass.getMethod("getNonBlockingMainQueueExecutor") .invoke(dispatchInstance); } catch (Throwable throwable) { throw new RuntimeException("Could not reflectively access Dispatch", throwable); } if (executor != null) { executor.execute(displayPumper); } else { throw new RuntimeException("Could not load executor"); } } else { Thread pumpThread = new Thread(displayPumper); pumpThread.start(); } while (!displayPumper.isReady()) ; Display display = displayPumper.getDisplay(); Shell shell = displayPumper.getShell(); Splash splashScreen = new Splash(display); splashScreen.updateState(BootSequence.CHECKING_LIBRARIES); checkPackagedLibrary(splashScreen, "enjarify", Constants.ENJARIFY_VERSION, BootSequence.CHECKING_ENJARIFY, BootSequence.CLEANING_ENJARIFY, BootSequence.MOVING_ENJARIFY); checkPackagedLibrary(splashScreen, "Krakatau", Constants.KRAKATAU_VERSION, BootSequence.CHECKING_KRAKATAU, BootSequence.CLEANING_KRAKATAU, BootSequence.MOVING_KRAKATAU); Helios.main(args, shell, splashScreen); while (!displayPumper.isDone()) { Thread.sleep(100); } } catch (Throwable t) { displayError(t); System.exit(1); } }
From source file:TryThread.java
public static void main(String[] args) { Thread first = new Thread(new TryThread("A ", "a ", 200L)); Thread second = new Thread(new TryThread("B ", "b ", 300L)); Thread third = new Thread(new TryThread("C ", "c ", 500L)); System.out.println("Press Enter when you have had enough...\n"); first.start(); second.start();/* w ww . ja va 2s . c o m*/ third.start(); try { System.in.read(); System.out.println("Enter pressed...\n"); } catch (IOException e) { System.out.println(e); } System.out.println("Ending main()"); return; }
From source file:TryThread.java
public static void main(String[] args) { Thread first = new Thread(new TryThread("A ", "a ", 200L), "name"); Thread second = new Thread(new TryThread("B ", "b ", 300L)); Thread third = new Thread(new TryThread("C ", "c ", 500L)); System.out.println("Press Enter when you have had enough...\n"); first.start(); second.start();//from ww w . jav a 2s. c o m third.start(); try { System.in.read(); System.out.println("Enter pressed...\n"); } catch (IOException e) { System.out.println(e); } System.out.println("Ending main()"); return; }