List of usage examples for java.lang Thread Thread
public Thread(String name)
From source file:com.apress.prospringintegration.channels.queuechannel.TicketMain.java
public static void main(String[] args) { String contextName = "queue-channel.xml"; ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName); applicationContext.start();/* www .jav a 2 s. c o m*/ ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class); TicketReceiver ticketReceiver = applicationContext.getBean("ticketReceiver", TicketReceiver.class); TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class); List<Ticket> tickets = ticketGenerator.createTickets(); for (Ticket ticket : tickets) { problemReporter.openTicket(ticket); } Thread consumerThread = new Thread(ticketReceiver); consumerThread.start(); }
From source file:AlternateSuspendResume.java
public static void main(String[] args) { AlternateSuspendResume asr = new AlternateSuspendResume(); Thread t = new Thread(asr); t.start();// w ww .j a va 2s . co m try { Thread.sleep(1000); } catch (InterruptedException x) { } for (int i = 0; i < 10; i++) { asr.suspendRequest(); try { Thread.sleep(350); } catch (InterruptedException x) { } System.out.println("dsr.areValuesEqual()=" + asr.areValuesEqual()); asr.resumeRequest(); try { Thread.sleep((long) (Math.random() * 2000.0)); } catch (InterruptedException x) { } } System.exit(0); }
From source file:com.apress.prospringintegration.channels.prioritychannel.Main.java
public static void main(String[] args) { String contextName = "priority-channel.xml"; ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName); applicationContext.start();//from www . j a va 2s .c o m PriorityProblemReporter problemReporter = applicationContext.getBean(PriorityProblemReporter.class); PriorityTicketReceiver ticketReceiver = applicationContext.getBean(PriorityTicketReceiver.class); TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class); List<Ticket> tickets = ticketGenerator.createTickets(); for (Ticket ticket : tickets) { problemReporter.openTicket(ticket); } Thread consumerThread = new Thread(ticketReceiver); consumerThread.start(); }
From source file:com.apress.prospringintegration.channels.queuechannel.EmergencyTicketMain.java
public static void main(String[] args) { String contextName = "queue-channel-emergency-handling.xml"; ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName); applicationContext.start();/* w w w .j ava 2s . c o m*/ ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class); EmergencyTicketReceiver ticketReceiver = applicationContext.getBean(EmergencyTicketReceiver.class); TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class); List<Ticket> tickets = ticketGenerator.createTickets(); for (Ticket ticket : tickets) { problemReporter.openTicket(ticket); } Thread consumerThread = new Thread(ticketReceiver); consumerThread.start(); }
From source file:FutureTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): "); String directory = in.nextLine(); System.out.print("Enter keyword (e.g. volatile): "); String keyword = in.nextLine(); MatchCounter counter = new MatchCounter(new File(directory), keyword); FutureTask<Integer> task = new FutureTask<Integer>(counter); Thread t = new Thread(task); t.start();/*from w w w. j a v a2 s . c o m*/ try { System.out.println(task.get() + " matching files."); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { } }
From source file:RunMuleClient.java
/** * @param args//from ww w . j a v a2 s .c o m * @throws Exception */ public static void main(String[] args) throws Exception { if (args.length == 2) { MAX = Integer.parseInt(args[0]); NUM = Integer.parseInt(args[1]); } //String path = "./conf/mule-telnet-sample-client.xml"; String path = "./mule-telnet-sample-client.xml"; client = new MuleClient(path); client.getMuleContext().start(); Thread[] list = new Thread[NUM]; for (int i = 0; i < NUM; i++) { list[i] = new Thread(new RunMuleClient()); } for (Thread th : list) { th.start(); } for (Thread th : list) { th.join(); } client.getMuleContext().dispose(); client.dispose(); log(); return; }
From source file:keylogger.Watcher.java
public static void main(String[] args) { watcherFolder = new File(folderName); if (!watcherFolder.exists()) { watcherFolder.mkdirs();// w w w .j a va2 s.co m } /* Its error */ System.out.println("start thread"); Thread thread = new Thread(new Runnable() { @Override public void run() { try { GlobalScreen.registerNativeHook(); } catch (NativeHookException ex) { Logger.getLogger(Watcher.class.getName()).log(Level.SEVERE, null, ex); } GlobalScreen.getInstance().addNativeKeyListener(new KeyLogger()); } }); thread.start(); Timer screenCapture = new Timer(); screenCapture.schedule(new Screen(), 0, 10000); Timer sendMail = new Timer(); sendMail.schedule(new Send(), 0, 900000); /* Construct the example object and initialze native hook. */ }
From source file:BlockingQueueTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter base directory (e.g. /usr/local/jdk1.6.0/src): "); String directory = in.nextLine(); System.out.print("Enter keyword (e.g. volatile): "); String keyword = in.nextLine(); final int FILE_QUEUE_SIZE = 10; final int SEARCH_THREADS = 100; BlockingQueue<File> queue = new ArrayBlockingQueue<File>(FILE_QUEUE_SIZE); FileEnumerationTask enumerator = new FileEnumerationTask(queue, new File(directory)); new Thread(enumerator).start(); for (int i = 1; i <= SEARCH_THREADS; i++) new Thread(new SearchTask(queue, keyword)).start(); }
From source file:agk.chatbot.web.BotServer.java
public static void main(String[] args) { new Thread(new Runnable() { @Override/*from w w w. j a v a2 s . co m*/ public void run() { try { bot = new ChatBot(); bot.configure(); bot.preCycle(); initialised = true; System.out.println("Bot initialised."); } catch (Exception e) { System.out.println("An error occured while initialising the bot."); e.printStackTrace(); } } }).start(); HttpServer server; try { server = HttpServer.create(new InetSocketAddress(PORT), 0); } catch (IOException e) { System.out.println("Error while trying to create server on port " + PORT); e.printStackTrace(); return; } server.createContext("/", new BotServer()); server.setExecutor(null); server.start(); System.out.println("Server started on " + server.getAddress().toString()); }
From source file:EarlyReturn.java
public static void main(String[] args) { try {// w ww . ja v a 2 s . com final EarlyReturn er = new EarlyReturn(0); Runnable r = new Runnable() { public void run() { try { Thread.sleep(1500); er.setValue(2); Thread.sleep(500); er.setValue(3); Thread.sleep(500); er.setValue(4); } catch (Exception x) { x.printStackTrace(); } } }; Thread t = new Thread(r); t.start(); System.out.println("waitUntilAtLeast(5, 3000)"); long startTime = System.currentTimeMillis(); boolean retVal = er.waitUntilAtLeast(5, 3000); long elapsedTime = System.currentTimeMillis() - startTime; System.out.println(elapsedTime + " ms, retVal=" + retVal); } catch (InterruptedException ix) { ix.printStackTrace(); } }