List of usage examples for java.lang Thread currentThread
@HotSpotIntrinsicCandidate public static native Thread currentThread();
From source file:com.dianping.dpsf.other.echo.EchoServer.java
/** * @param args//w w w . j a v a2 s . c om * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { Thread.currentThread().setName("=============EchoSerer1============"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server.xml"); if (args.length == 0) { //stand alone start CountDownLatch latch = new CountDownLatch(1); latch.await(); } }
From source file:com.dianping.dpsf.other.echo.EchoServer2.java
/** * @param args/* w w w . jav a 2 s . c o m*/ * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { Thread.currentThread().setName("=============EchoSerer2============"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server2.xml"); if (args.length == 0) { //stand alone start CountDownLatch latch = new CountDownLatch(1); latch.await(); } }
From source file:com.dianping.dpsf.other.echo.EchoServer3.java
/** * @param args/*from www . j a v a2 s .co m*/ * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { Thread.currentThread().setName("=============EchoSerer3============"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server3.xml"); if (args.length == 0) { //stand alone start CountDownLatch latch = new CountDownLatch(1); latch.await(); } }
From source file:com.dianping.dpsf.other.echo.EchoServer4.java
/** * @param args/* w w w . j a va2 s . com*/ * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { Thread.currentThread().setName("=============EchoSerer4============"); ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server4.xml"); if (args.length == 0) { //stand alone start CountDownLatch latch = new CountDownLatch(1); latch.await(); } }
From source file:Test.java
public static void main(String[] args) throws Exception { AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(Paths.get("/asynchronous.txt"), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE); CompletionHandler<Integer, Object> handler = new CompletionHandler<Integer, Object>() { @Override/*from ww w . j a va 2s . co m*/ public void completed(Integer result, Object attachment) { System.out.println("Attachment: " + attachment + " " + result + " bytes written"); System.out.println("CompletionHandler Thread ID: " + Thread.currentThread().getId()); } @Override public void failed(Throwable e, Object attachment) { System.err.println("Attachment: " + attachment + " failed with:"); e.printStackTrace(); } }; System.out.println("Main Thread ID: " + Thread.currentThread().getId()); fileChannel.write(ByteBuffer.wrap("Sample".getBytes()), 0, "First Write", handler); fileChannel.write(ByteBuffer.wrap("Box".getBytes()), 0, "Second Write", handler); }
From source file:TestObjectPool.java
public static void main(String args[]) throws Exception { GenericObjectPool pool = new GenericObjectPool(); pool.setFactory(new EmployeeFactory()); /*First way of initializing pool pool.setMinIdle(5);/*from w w w . j a v a2s .com*/ pool.setTimeBetweenEvictionRunsMillis(500); Thread.currentThread().sleep(600);*/ /* second, and preferred way */ for(int i = 0; i < 5; ++i) { pool.addObject(); } // pool.setTestOnReturn(true); pool.setMinEvictableIdleTimeMillis(1000); pool.setTimeBetweenEvictionRunsMillis(600); System.err.println("Number of employees in pool: " + pool.getNumIdle()); Thread.currentThread().sleep(1500); Employee employee = (Employee)pool.borrowObject(); employee.setName("Fred Flintstone"); employee.doWork(); System.err.println("Employee: " + employee); pool.returnObject(employee); System.err.println("Number of employees in pool: " + pool.getNumIdle()); }
From source file:Main.java
public static void main(String[] args) throws Exception { AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open(); String host = "localhost"; int port = 8989; InetSocketAddress sAddr = new InetSocketAddress(host, port); server.bind(sAddr);//from w w w .j a va 2s . c o m System.out.format("Server is listening at %s%n", sAddr); Attachment attach = new Attachment(); attach.server = server; server.accept(attach, new ConnectionHandler()); Thread.currentThread().join(); }
From source file:Main.java
public static void main(String[] args) throws Exception { AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(); SocketAddress serverAddr = new InetSocketAddress("localhost", 8989); Future<Void> result = channel.connect(serverAddr); result.get();// w ww .ja v a 2 s .com System.out.println("Connected"); Attachment attach = new Attachment(); attach.channel = channel; attach.buffer = ByteBuffer.allocate(2048); attach.isRead = false; attach.mainThread = Thread.currentThread(); Charset cs = Charset.forName("UTF-8"); String msg = "Hello"; byte[] data = msg.getBytes(cs); attach.buffer.put(data); attach.buffer.flip(); ReadWriteHandler readWriteHandler = new ReadWriteHandler(); channel.write(attach.buffer, attach, readWriteHandler); attach.mainThread.join(); }
From source file:com.microsoft.tfs.client.clc.vc.Main.java
public static void main(final String[] args) { TELoggingConfiguration.configure();/*from w ww .ja va2 s.c o m*/ final Log log = LogFactory.getLog(Main.class); log.debug("Entering Main"); //$NON-NLS-1$ Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread t, final Throwable e) { log.error("Unhandled exception in the thread " + t.getName() + " : ", e); //$NON-NLS-1$ //$NON-NLS-2$ /* * Let the shutdown manager clean up any registered items. */ try { log.debug("Shutting down"); //$NON-NLS-1$ ShutdownManager.getInstance().shutdown(); log.debug("Has shut down"); //$NON-NLS-1$ } catch (final Exception ex) { log.error("Unhandled exception during shutdown: ", ex); //$NON-NLS-1$ } } }); /* * Please don't do any fancy work in this method, because we have a CLC * test harness that calls Main.run() directly, and we can't test * functionality in this method (because this method can't return a * status code but exits the process directly, which kind of hoses any * test framework). */ final Main main = new Main(); int ret = ExitCode.FAILURE; try { ret = main.run(args); } catch (final Throwable e) { log.error("Unhandled exception reached Main: ", e); //$NON-NLS-1$ } finally { /* * Let the shutdown manager clean up any registered items. */ try { log.info("Shutting down"); //$NON-NLS-1$ ShutdownManager.getInstance().shutdown(); log.info("Has shut down"); //$NON-NLS-1$ } catch (final Exception e) { log.error("Unhandled exception during shutdown: ", e); //$NON-NLS-1$ } } System.exit(ret); }
From source file:SyncExecExample.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); final Runnable print = new Runnable() { public void run() { System.out.println("Print from thread: \t" + Thread.currentThread().getName()); }/*from www. ja v a 2s. c o m*/ }; final Thread applicationThread = new Thread("applicationThread") { public void run() { System.out.println("Hello from thread: \t" + Thread.currentThread().getName()); display.syncExec(print); System.out.println("Bye from thread: \t" + Thread.currentThread().getName()); } }; shell.setText("syncExec Example"); shell.setSize(300, 100); Button button = new Button(shell, SWT.CENTER); button.setText("Click to start"); button.setBounds(shell.getClientArea()); button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { applicationThread.start(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) {// If no more entries in event queue display.sleep(); } } display.dispose(); }