List of usage examples for java.lang Thread start
public synchronized void start()
From source file:Main.java
public static void main(String[] args) throws Exception { Thread previousThread = null; for (int i = 0; i < 20; i++) { JobRunnable job = new JobRunnable(i, previousThread); Thread thread = new Thread(job, "T-" + i); thread.start(); previousThread = thread;// ww w . j av a 2s .c om } if (previousThread != null) { previousThread.join(); } System.out.println("Program done."); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { int port = 9000; ServerSocket server = new ServerSocket(port); while (true) { Socket socket = server.accept(); Thread stuffer = new StuffThread(socket); stuffer.start(); }//from w ww. j a va 2 s . c o m }
From source file:TestSynchronized.java
public static void main(String[] args) throws Exception { final TestSynchronized tus = new TestSynchronized(); Runnable runA = new Runnable() { public void run() { tus.performATask(1);/*w w w . j av a 2 s . c o m*/ } }; Thread ta = new Thread(runA, "threadA"); ta.start(); Thread.sleep(2000); Runnable runB = new Runnable() { public void run() { tus.performATask(2); } }; Thread tb = new Thread(runB, "threadB"); tb.start(); }
From source file:com.surveypanel.form.test.Runner.java
/** * @param args// ww w . j a v a2s. com */ public static void main(String[] args) { try { init(surveyId); Thread[] runners = new Thread[100]; for (int j = 0; j < runners.length; j++) { runners[j] = new Thread(new FormRun(formFactory, jsManager, surveyId)); } for (Thread thread : runners) { thread.start(); } Thread.sleep(1000); } catch (Exception e) { log.error(e); } }
From source file:ThreadDemo.java
public static void main(String args[]) { ThreadDemo trace = new ThreadDemo(); Thread t = new Thread(trace); // this will call run() method t.start(); // returns a map of stack traces Map m = Thread.getAllStackTraces(); }
From source file:TestUnsynchronized.java
public static void main(String[] args) throws Exception { final TestUnsynchronized tus = new TestUnsynchronized(); Runnable runA = new Runnable() { public void run() { tus.doAction(3);//from www .j ava 2 s. co m } }; Thread ta = new Thread(runA, "threadA"); ta.start(); Thread.sleep(2000); Runnable runB = new Runnable() { public void run() { tus.doAction(7); } }; Thread tb = new Thread(runB, "threadB"); tb.start(); }
From source file:ThreadDemo.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); // this will call run() function t.start(); }
From source file:GetPriority.java
public static void main(String[] args) { System.out.println(/*ww w . j a va 2s .c om*/ "in main() - Thread.currentThread().getPriority()=" + Thread.currentThread().getPriority()); System.out.println("in main() - Thread.currentThread().getName()=" + Thread.currentThread().getName()); Thread threadA = new Thread(makeRunnable(), "threadA"); threadA.start(); try { Thread.sleep(3000); } catch (InterruptedException x) { } System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority()); }
From source file:Main.java
public static void main(String args[]) { Thread t = new Thread(new ThreadDemo()); System.out.println("thread = " + t); t.start(); }
From source file:StaticBlock.java
public static void main(String[] args) { Runnable runA = new Runnable() { public void run() { StaticBlock.staticA();/*from w w w . j a v a 2 s . co m*/ } }; Thread threadA = new Thread(runA, "A"); threadA.start(); try { Thread.sleep(200); } catch (InterruptedException x) { } Runnable runB = new Runnable() { public void run() { StaticBlock.staticB(); } }; Thread threadB = new Thread(runB, "B"); threadB.start(); }