List of usage examples for java.lang Thread start
public synchronized void start()
From source file:Main.java
public static void main(String a[]) throws Exception { MyThread tt1 = new MyThread(50); MyThread tt2 = new MyThread(75); Thread t1 = new Thread(tt1, "Test thread 1"); Thread t2 = new Thread(tt2, "Test thread 2"); t1.start(); t2.start();/*from ww w .j ava 2s .c om*/ t1.join(); t2.join(); }
From source file:Pipe.java
public static void main(String args[]) throws Exception { PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(in); Sender s = new Sender(out); Receiver r = new Receiver(in); Thread t1 = new Thread(s); Thread t2 = new Thread(r); t1.start(); t2.start();//from ww w . j a va2s . c o m }
From source file:Main.java
public static void main(String[] args) { // Create two Thread objects Thread t1 = new Thread(Main::print); Thread t2 = new Thread(Main::print); // Start both threads t1.start(); t2.start();/*ww w. j a v a2s.c om*/ }
From source file:RunMuleClient.java
/** * @param args//from w w w.j a v a 2 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:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("Executing " + t.getName()); t.start(); if (!t.isInterrupted()) { t.interrupt();//from www. j a v a 2s . co m } try { t.join(); } catch (InterruptedException e) { } }
From source file:Main.java
public static void main(String[] args) throws Exception { Thread thread1 = new Thread(new TestThread(1)); Thread thread2 = new Thread(new TestThread(2)); thread1.start(); thread2.start();/*w w w . jav a 2 s. c om*/ thread1.join(); thread2.join(); }
From source file:ThreadIDMain.java
public static void main(String[] args) { ThreadID tid = new ThreadID(); ThreadIDMain shared = new ThreadIDMain(tid); try {/* w w w . j a v a 2s. c o m*/ Thread threadA = new Thread(shared, "threadA"); threadA.start(); Thread.sleep(500); Thread threadB = new Thread(shared, "threadB"); threadB.start(); Thread.sleep(500); Thread threadC = new Thread(shared, "threadC"); threadC.start(); } catch (InterruptedException x) { } }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("Executing " + t.getName()); t.start(); if (!t.interrupted()) { t.interrupt();//from w w w . j a v a 2 s .c o m } // block until other threads finish try { t.join(); } catch (InterruptedException e) { } }
From source file:SwingSuspendResume.java
public static void main(String[] args) { SwingSuspendResume vsr = new SwingSuspendResume(); Thread t = new Thread(vsr); t.start(); JFrame f = new JFrame(); f.setContentPane(vsr);//from w ww. j ava 2 s . com f.setSize(320, 200); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); }
From source file:ThreadedEchoServer.java
public static void main(String[] args) { try {//w w w .ja v a2 s. c o m int i = 1; ServerSocket s = new ServerSocket(8189); while (true) { Socket incoming = s.accept(); System.out.println("Spawning " + i); Runnable r = new ThreadedEchoHandler(incoming); Thread t = new Thread(r); t.start(); i++; } } catch (IOException e) { e.printStackTrace(); } }