List of usage examples for java.lang Thread Thread
public Thread(Runnable target, String name)
From source file:MainClass.java
public static void main(String[] args) { ThreadGroup tg = new OverrideThreadGroup(); Thread t = new Thread(tg, new MainClass()); t.start();/*w w w . j av a 2 s. c om*/ }
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);/*from ww w. j a v 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: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();// w ww . j a va 2s. c o m second.start(); 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:ThreadIDMain.java
public static void main(String[] args) { ThreadID tid = new ThreadID(); ThreadIDMain shared = new ThreadIDMain(tid); try {//from w w w .j a v a 2 s. com 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:StaticSync.java
public static void main(String[] args) { try {/*from w w w . j a v a 2 s.c om*/ Runnable r = new Runnable() { public void run() { print("getNextSerialNum()=" + getNextSerialNum()); } }; Thread threadA = new Thread(r, "threadA"); threadA.start(); Thread.sleep(1500); Thread threadB = new Thread(r, "threadB"); threadB.start(); Thread.sleep(500); Thread threadC = new Thread(r, "threadC"); threadC.start(); Thread.sleep(2500); Thread threadD = new Thread(r, "threadD"); threadD.start(); } catch (InterruptedException x) { // ignore } }
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 av a2 s. c o 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(); }
From source file:MyThread.java
public static void main(String args[]) throws Exception { Thread thrd = new Thread(new MyThread(), "MyThread #1"); Thread thrd2 = new Thread(new MyThread(), "MyThread #2"); thrd.start();// w ww .jav a 2s . co m Thread.sleep(1000); thrd.interrupt(); thrd2.start(); Thread.sleep(4000); thrd2.interrupt(); }
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 w ww . j a va 2 s .c o 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:GetPriority.java
public static void main(String[] args) { System.out.println(// w w w.j a v a 2s. c o m "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:OnlyOneInMethod.java
public static void main(String[] args) { final OnlyOneInMethod ooim = new OnlyOneInMethod("obj1"); Runnable runA = new Runnable() { public void run() { ooim.doStuff(3);//w ww . ja va 2 s. c o m } }; Thread threadA = new Thread(runA, "threadA"); threadA.start(); try { Thread.sleep(200); } catch (InterruptedException x) { } Runnable runB = new Runnable() { public void run() { ooim.doStuff(7); } }; Thread threadB = new Thread(runB, "threadB"); threadB.start(); }