List of usage examples for java.lang Thread sleep
public static native void sleep(long millis) throws InterruptedException;
From source file:StaticBlock.java
public static void main(String[] args) { Runnable runA = new Runnable() { public void run() { StaticBlock.staticA();//from ww w. j a v a 2 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 { ThreadGroup group = new ThreadGroup("Group"); ThreadGroup newGroup = new ThreadGroup(group, "new group"); MyThread t1 = new MyThread(group, "Thread1"); MyThread t2 = new MyThread(group, "Thread2"); t1.start();//from w ww. j a v a 2 s .co m t2.start(); Thread.sleep(1000); System.out.println(group.activeCount() + " threads in thread group..."); Thread th[] = new Thread[group.activeCount()]; group.enumerate(th); for (Thread t : th) { System.out.println(t.getName()); } Thread.sleep(1000); System.out.println(group.activeCount() + " threads in thread group..."); group.interrupt(); }
From source file:JNLPTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container content = frame.getContentPane(); JLabel label = new JLabel("Hello, JNLP"); content.add(label, BorderLayout.CENTER); frame.setSize(200, 200);//from w ww. j av a2s . c o m frame.show(); try { Thread.sleep(5000); } catch (InterruptedException ignored) { } finally { System.exit(0); } }
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);//w w w .j a v a 2s . 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:AlternateStop.java
public static void main(String[] args) { AlternateStop as = new AlternateStop(); Thread t = new Thread(as); t.start();/*from www . j av a2s . c o m*/ try { Thread.sleep(2000); } catch (InterruptedException x) { } as.stopRequest(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("test.txt"); AsynchronousFileChannel afc = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE); WriteHandler handler = new WriteHandler(); ByteBuffer dataBuffer = getDataBuffer(); Attachment attach = new Attachment(); attach.asyncChannel = afc;/*from w w w. j a va 2s . co m*/ attach.buffer = dataBuffer; attach.path = path; afc.write(dataBuffer, 0, attach, handler); System.out.println("Sleeping for 5 seconds..."); Thread.sleep(5000); }
From source file:be.anova.course.camel.beans.Main.java
public static void main(String[] args) { try {//from w w w . j a v a 2s . c o m ApplicationContext context = new ClassPathXmlApplicationContext("context.xml"); Thread.sleep(60000); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.apress.prospringintegration.jmx.JmxAttributePolling.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmx/attribute-polling.xml"); try {//from w w w .j a v a2 s . co m Thread.sleep(180000); } catch (InterruptedException e) { //do nothing } context.stop(); }
From source file:be.anova.course.camel.basic.Main.java
public static void main(String[] args) { try {/* ww w.j a v a 2s .c om*/ ApplicationContext context = new ClassPathXmlApplicationContext("context.xml"); Thread.sleep(60000); } catch (Exception e) { e.printStackTrace(); } }
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); first.start();/* www.j ava 2 s. com*/ second.start(); third.start(); try { Thread.sleep(3000); first.interrupt(); second.interrupt(); third.interrupt(); } catch (Exception e) { System.out.println(e); } }