Example usage for java.lang Thread currentThread

List of usage examples for java.lang Thread currentThread

Introduction

In this page you can find the example usage for java.lang Thread currentThread.

Prototype

@HotSpotIntrinsicCandidate
public static native Thread currentThread();

Source Link

Document

Returns a reference to the currently executing thread object.

Usage

From source file:de.topobyte.collections.util.gen.GenListToArray.java

public static void main(String[] args) throws IOException {
    InputStream input = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("listAsArray.template");
    String template = IOUtils.toString(input);

    for (PrimitiveType type : PrimitiveType.values()) {
        System.out.println(InstanceCreator.create(template, type));
    }//  ww  w .j  a v  a2s  .  c  o m
}

From source file:de.topobyte.collections.util.gen.GenCollectionToArray.java

public static void main(String[] args) throws IOException {
    InputStream input = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("collectionAsArray.template");
    String template = IOUtils.toString(input);

    for (PrimitiveType type : PrimitiveType.values()) {
        System.out.println(InstanceCreator.create(template, type));
    }/*from   w w  w.  java 2s .c o  m*/
}

From source file:gridool.GridMain.java

public static void main(String[] args) {
    final Thread parent = Thread.currentThread();
    final GridServer grid = new GridServer();
    try {//  w ww . j a  v a2s  .  c  o m
        grid.start();
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                parent.interrupt();
            }
        });
    } catch (InternalException ie) {
        shutdown(grid, ie);
    } catch (Throwable e) {
        shutdown(grid, e);
    }
    try {
        Thread.currentThread().join();
    } catch (InterruptedException e) {
        ;
    } finally {
        try {
            grid.shutdown(true);
        } catch (RemoteException re) {
            ;
        }
    }
}

From source file:io.gravitee.gateway.platforms.jetty.bootstrap.Bootstrap.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    t.setName("graviteeio-gateway");

    final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(JettyConfiguration.class);
    ctx.registerShutdownHook();// w w w.  j a  v a2 s.  c  om
    ctx.refresh();

    try {
        final Node node = ctx.getBean(Node.class);
        node.start();

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                LoggerFactory.getLogger(Bootstrap.class).info("Shutting-down Gravitee Gateway...");
                node.stop();
                ctx.close();
            }
        });
    } catch (Exception ex) {
        LOGGER.error("Unable to start Gravitee Gateway", ex);
    }
}

From source file:com.domeastudio.util.JarClassLoader.java

public static void main(String[] args) {
    URL[] urls = new URL[] {};
    JarClassLoader jarClassLoader = new JarClassLoader(urls, Thread.currentThread().getContextClassLoader());
    try {/*from  w w  w  . jav a2  s  .  c  o  m*/
        Geometry geometrySource = GeometryFormateHelper.getGeometry("POLYGON((1 1,3 4,6 7,10 45,1 1))");
        Geometry geometryTarget = GeometryFormateHelper.getGeometry("POINT(1 1)");
        //String path=jarClassLoader.getPath("lib/utility-1.0-SNAPSHOT.jar");
        jarClassLoader.addJar("utility-1.0-SNAPSHOT.jar");
        Class<?> clazz = jarClassLoader.loadClass("com.domeastudio.util.gis.SpatialOperationHelper");
        Class[] parameterTypes = new Class[] { Geometry.class, Geometry.class };
        Method method = clazz.getMethod("touches", parameterTypes);
        Boolean f = (Boolean) method.invoke(null, geometrySource, geometryTarget);
        System.out.println(f);
        jarClassLoader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // System.out.println("null:" + readWriteLicense.getLicenseName());
    // System.out.println("" + StringHelper.isEmptyAndBlank(""));
    //System.out.println("" + StringHelper.isEmptyAndBlank(" "));
}

From source file:ThreadState.java

public static void main(String[] args) throws InterruptedException {
    Object syncObject = new Object();
    ThreadState ts = new ThreadState(syncObject);
    System.out.println("Before start()-ts.isAlive():" + ts.isAlive());
    System.out.println("#1:" + ts.getState());

    ts.start();//  w  w  w.  ja  v a 2  s.co m
    System.out.println("After start()-ts.isAlive():" + ts.isAlive());
    System.out.println("#2:" + ts.getState());
    ts.setWait(true);

    Thread.currentThread().sleep(100);

    synchronized (syncObject) {
        System.out.println("#3:" + ts.getState());
        ts.setWait(false);
        syncObject.notifyAll();
    }

    Thread.currentThread().sleep(2000);
    System.out.println("#4:" + ts.getState());
    ts.setKeepRunning(false);

    Thread.currentThread().sleep(2000);
    System.out.println("#5:" + ts.getState());
    System.out.println("At the   end. ts.isAlive():" + ts.isAlive());
}

From source file:org.brnvrn.Main.java

public static void main(String[] args) {

    Document doc = null; // the HTML tool page
    Document docObsolete = null;/*from   w w  w  .  jav  a2  s .c o m*/
    try {
        //Document doc = Jsoup.connect("http://taskwarrior.org/tools/").get();
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream input = classloader.getResourceAsStream("Taskwarrior-Tools.html");
        doc = Jsoup.parse(input, "UTF-8", "http://taskwarrior.org/");
        input = classloader.getResourceAsStream("Taskwarrior-Tools-Obsolete.html");
        docObsolete = Jsoup.parse(input, "UTF-8", "http://taskwarrior.org/");
    } catch (IOException e) {
        e.printStackTrace();
    }

    List<Tool> tools = new ArrayList<Tool>(100);
    ObjectMapper objectMapper = parseDocument(tools, doc, false);
    objectMapper = parseDocument(tools, docObsolete, true);

    try {
        objectMapper.writeValue(new FileOutputStream("data-tools.json"), tools);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Logging.java

public static void main(String args[]) throws Exception {
    FileOutputStream errors = new FileOutputStream("StdErr.txt", true);
    PrintStream stderr = new PrintStream(errors);
    PrintWriter errLog = new PrintWriter(errors, true);
    System.setErr(stderr);//from  w  ww  . ja v a  2 s. c  o m

    String query = "SELECT Name,Description,Qty,Cost,Sell_Price FROM Stock";

    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:Inventory");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String name = rs.getString("Name");
            String desc = rs.getString("Description");
            int qty = rs.getInt("Qty");
            float cost = rs.getFloat("Cost");
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace(errLog);
    } catch (SQLException e) {
        System.err.println((new GregorianCalendar()).getTime());
        System.err.println("Thread: " + Thread.currentThread());
        System.err.println("ErrorCode: " + e.getErrorCode());
        System.err.println("SQLState:  " + e.getSQLState());
        System.err.println("Message:   " + e.getMessage());
        System.err.println("NextException: " + e.getNextException());
        e.printStackTrace(errLog);
        System.err.println();
    }
    stderr.close();
}

From source file:com.curso.ejemplotareaplanificada.Principal.java

/**
 * @param args the command line arguments
 *//*from  www .  j ava2s .c om*/
public static void main(String[] args) {
    //solo estamos usando anotaciones
    //en esta clase no hay nada de los metodos planificados porque esos ya los llama spring solito
    //esta clase es para pegarnos con los servicios asincronos
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Configuracion.class);
    System.out.println("Contexto cargado");
    ServicioAsincrono sa = ctx.getBean(ServicioAsincrono.class);
    System.out.println("Hilo principal " + Thread.currentThread());

    //Este metodo devuelve void asi que el hilo arranca un nuevo hilo pero continua sin esperar ni ahora ni a un futuro
    sa.metodoUno();

    //Este metodo devuelve un futuro, y cuando llamemos a get espera 5 segundos a ver si termina el nuevo hilo
    //Si sobre pasa esos 5 segundos lanza una excepcion
    Future<Double> numero = sa.factorial(100);
    try {
        System.out.println("El factorial es desde un Future:" + numero.get(5L, TimeUnit.SECONDS));
    } catch (InterruptedException | ExecutionException | TimeoutException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Este metodo devuelve un escuchable
    ListenableFuture<Double> valor = sa.factorialLf(100);
    //Al metodo escuchable le aadimos una clase anonima de tipo llamable con dos metodos, uno que se ejecutara cuando acabe con exito
    //y otro si no acaba correctamente
    valor.addCallback(new ListenableFutureCallback<Double>() {

        @Override
        public void onSuccess(Double result) {
            System.out.println("El resultado es desde un ListenableFuture: " + result);
        }

        @Override
        public void onFailure(Throwable ex) {
            LOG.log(Level.SEVERE, "Ha ocurrido un error:", ex);
        }
    });
}

From source file:io.lightlink.excel.StreamingExcelTransformer.java

public static void main(String[] args) throws Exception {

    System.out.println("StreamingExcelTransformer.main");
    InputStream template = Thread.currentThread().getContextClassLoader().getResourceAsStream("template.xlsx");
    FileOutputStream out = new FileOutputStream("result.xlsx");

    new StreamingExcelTransformer().doExport(template, out, new ExcelStreamVisitor() {
        @Override/*w ww.j a  v a2 s  .co m*/
        public void visit(RowNode rowNode, RowPrintCallback rowPrintCallback) {

            rowNode.getCells().addAll(rowNode.getCells());

            rowPrintCallback.printRowNode(rowNode);
            rowPrintCallback.printRowNode(rowNode);
            rowPrintCallback.printRowNode(rowNode);
            rowPrintCallback.printRowNode(rowNode);

        }
    });

}