Example usage for java.lang Thread run

List of usage examples for java.lang Thread run

Introduction

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

Prototype

@Override
public void run() 

Source Link

Document

If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Usage

From source file:it.geosolutions.sfs.web.Start.java

public static void main(String[] args) {
    final Server jettyServer = new Server();

    try {// w  w  w.  jav  a2s .c o  m
        SocketConnector conn = new SocketConnector();
        String portVariable = System.getProperty("jetty.port");
        int port = parsePort(portVariable);
        if (port <= 0)
            port = 8082;
        conn.setPort(port);
        conn.setAcceptQueueSize(100);
        conn.setMaxIdleTime(1000 * 60 * 60);
        conn.setSoLingerTime(-1);

        // Use this to set a limit on the number of threads used to respond requests
        // BoundedThreadPool tp = new BoundedThreadPool();
        // tp.setMinThreads(8);
        // tp.setMaxThreads(8);
        // conn.setThreadPool(tp);

        // SSL host name given ?
        String sslHost = System.getProperty("ssl.hostname");
        SslSocketConnector sslConn = null;
        //            if (sslHost!=null && sslHost.length()>0) {   
        //                Security.addProvider(new BouncyCastleProvider());
        //                sslConn = getSslSocketConnector(sslHost);
        //            }

        if (sslConn == null) {
            jettyServer.setConnectors(new Connector[] { conn });
        } else {
            conn.setConfidentialPort(sslConn.getPort());
            jettyServer.setConnectors(new Connector[] { conn, sslConn });
        }

        /*Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);;
        constraint.setRoles(new String[]{"user","admin","moderator"});
        constraint.setAuthenticate(true);
                 
        ConstraintMapping cm = new ConstraintMapping();
        cm.setConstraint(constraint);
        cm.setPathSpec("/*");
                
        SecurityHandler sh = new SecurityHandler();
        sh.setUserRealm(new HashUserRealm("MyRealm","/Users/jdeolive/realm.properties"));
        sh.setConstraintMappings(new ConstraintMapping[]{cm});
                
        WebAppContext wah = new WebAppContext(sh, null, null, null);*/
        WebAppContext wah = new WebAppContext();
        wah.setContextPath("/sfs");
        wah.setWar("src/main/webapp");

        jettyServer.setHandler(wah);
        wah.setTempDirectory(new File("target/work"));
        //this allows to send large SLD's from the styles form
        wah.getServletContext().getContextHandler().setMaxFormContentSize(1024 * 1024 * 2);

        String jettyConfigFile = System.getProperty("jetty.config.file");
        if (jettyConfigFile != null) {
            //                log.info("Loading Jetty config from file: " + jettyConfigFile);
            (new XmlConfiguration(new FileInputStream(jettyConfigFile))).configure(jettyServer);
        }

        jettyServer.start();

        /*
         * Reads from System.in looking for the string "stop\n" in order to gracefully terminate
         * the jetty server and shut down the JVM. This way we can invoke the shutdown hooks
         * while debugging in eclipse. Can't catch CTRL-C to emulate SIGINT as the eclipse
         * console is not propagating that event
         */
        Thread stopThread = new Thread() {
            @Override
            public void run() {
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                String line;
                try {
                    while (true) {
                        line = reader.readLine();
                        if ("stop".equals(line)) {
                            jettyServer.stop();
                            System.exit(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        };
        stopThread.setDaemon(true);
        stopThread.run();

        // use this to test normal stop behaviour, that is, to check stuff that
        // need to be done on container shutdown (and yes, this will make 
        // jetty stop just after you started it...)
        // jettyServer.stop(); 
    } catch (Exception e) {
        //            log.log(Level.SEVERE, "Could not start the Jetty server: " + e.getMessage(), e);

        if (jettyServer != null) {
            try {
                jettyServer.stop();
            } catch (Exception e1) {
                //                    log.log(Level.SEVERE,
                //                        "Unable to stop the " + "Jetty server:" + e1.getMessage(), e1);
            }
        }
    }
}

From source file:Main.java

public static void startThread(Thread t, boolean ativo) {
    if (ativo) {/*from   w w  w  .j  a v  a  2  s. c  o m*/
        t.start();
    } else {
        t.run();
    }
}

From source file:com.meetingninja.csse.database.AgendaDatabaseAdapter.java

public static JsonNode update(String agendaID, Map<String, String> key_values)
        throws JsonGenerationException, IOException, InterruptedException {
    // prepare POST payload
    ByteArrayOutputStream json = new ByteArrayOutputStream();
    // this type of print stream allows us to get a string easily
    PrintStream ps = new PrintStream(json);

    // Create a generator to build the JSON string
    JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8);
    for (String key : key_values.keySet()) {
        jgen.flush();/*from   w w w. j  a v  a2  s. com*/
        // Build JSON Object
        jgen.writeStartObject();
        jgen.writeStringField(Keys.Agenda.ID, agendaID);
        jgen.writeStringField("field", key);
        jgen.writeStringField("value", key_values.get(key));
        jgen.writeEndObject();
        jgen.writeRaw("\f"); // write a form-feed to separate the payloads
    }

    jgen.close();
    // Get JSON Object payload from print stream
    String payload = json.toString("UTF8");
    ps.close();
    // The backend can only update a single field at a time
    String[] payloads = payload.split("\f\\s*"); // split at each form-feed
    Thread t = new Thread(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.getLocalizedMessage();
            }
        }
    }));
    String response = "";
    for (String p : payloads) {
        t.run();
        response = updateHelper(p);
    }
    return MAPPER.readTree(response);
}

From source file:com.wbtech.ums.UmsAgent.java

/**
 * @param context/*from   w  w  w.  j a v  a  2 s .c o  m*/
 */
private static void postonResume(Context context) {
    if (!CommonUtil.isNetworkAvailable(context)) {
        setDefaultReportPolicy(context, 0);
    } else {
        if (UmsAgent.isPostFile) {
            Thread thread = new GetInfoFromFile(context);
            thread.run();
            UmsAgent.isPostFile = false;
        }

    }

    isCreateNewSessionID(context);

    activities = CommonUtil.getActivityName(context);
    try {
        if (session_id == null) {
            generateSeesion(context);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    start_millis = CommonUtil.getTime();
    start = Long.valueOf(System.currentTimeMillis());

}

From source file:com.meetingninja.csse.database.UserDatabaseAdapter.java

public static User update(String userID, Map<String, String> key_values)
        throws JsonGenerationException, IOException, InterruptedException {
    // prepare POST payload
    ByteArrayOutputStream json = new ByteArrayOutputStream();
    // this type of print stream allows us to get a string easily
    PrintStream ps = new PrintStream(json);

    // Create a generator to build the JSON string
    JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8);
    for (String key : key_values.keySet()) {
        if (key.equals(Keys.User.EMAIL) && !Utilities.isValidEmailAddress(key_values.get(Keys.User.EMAIL)))
            throw new IOException("Error : [Update User] Incorrect email format");
        else {// w w  w.  java  2  s.c  o m
            jgen.flush();
            // Build JSON Object
            jgen.writeStartObject();
            jgen.writeStringField(Keys.User.ID, userID);
            jgen.writeStringField("field", key);
            jgen.writeStringField("value", key_values.get(key));
            jgen.writeEndObject();
            jgen.writeRaw("\f");
        }
    }

    jgen.close();
    // Get JSON Object payload from print stream
    String payload = json.toString("UTF8");
    ps.close();
    String[] payloads = payload.split("\f\\s*");

    Thread t = new Thread(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.getLocalizedMessage();
            }
        }
    }));
    String response = "";
    for (String p : payloads) {
        t.run();
        response = updateHelper(p);
    }
    return parseUser(MAPPER.readTree(response));
}

From source file:com.espertech.esper.regression.view.TestMultithreadedTimeWin.java

public void testMultithreaded() throws Exception {
    int numSymbols = 1;
    int numThreads = 4;
    int numEventsPerThread = 50000;
    double timeWindowSize = 0.2;

    // Set up threads, statements and listeners
    setUp(numSymbols, numThreads, numEventsPerThread, timeWindowSize);

    // Start threads
    long startTime = System.currentTimeMillis();
    for (Thread thread : threads) {
        thread.run();
    }//from  w  ww  .j a va  2s  . c  om

    // Wait for completion
    for (Thread thread : threads) {
        thread.join();
    }
    long endTime = System.currentTimeMillis();

    // Check listener results
    long totalReceived = 0;
    for (ResultUpdateListener listener : listeners) {
        totalReceived += listener.getNumReceived();
        assertFalse(listener.isCaughtRuntimeException());
    }
    double numTimeWindowAdvancements = (endTime - startTime) / 1000 / timeWindowSize;

    log.info("Completed, expected=" + numEventsPerThread * numThreads + " numTimeWindowAdvancements="
            + numTimeWindowAdvancements + " totalReceived=" + totalReceived);
    assertTrue(totalReceived < numEventsPerThread * numThreads + numTimeWindowAdvancements + 1);
    assertTrue(totalReceived >= numEventsPerThread * numThreads);
}

From source file:com.kumarvv.setl.Setl.java

/**
 * start the process/*from  w  w w.  j  a v  a2  s .  c o m*/
 * @param def
 */
protected void start(final Def def) {
    if (def == null) {
        Logger.error("Invalid or blank definition");
        return;
    }

    LoggingContext.put("defName", def.getName());
    LoggingContext.put("loadTable", "");

    Logger.info("Processing " + def.getName());

    Status status = new Status((s) -> printStatEvery(s));
    SetlProcessor processor = new SetlProcessor(status, def);
    Thread t = new Thread(processor);
    t.run();

    try {
        t.join();
    } catch (InterruptedException ie) {
    }

    printStatAll(status);
}

From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.TaskExecutorThreadExecutor.java

public void execute(final Thread thread) {
    taskExecutor.execute(new SchedulingAwareRunnable() {
        public boolean isLongLived() {
            return true;
        }//from  www .  j a  va  2 s  . com

        public void run() {
            thread.run();
        }
    });
}

From source file:org.hachreak.projects.networkcodingsip2peer.peer.SimplePeer.java

/**
 * Join the network/* w w  w.  j av a  2  s. c o  m*/
 * 
 * @throws NoBootstrapConfiguredException
 */
public void joinBootstrapPeer(FullFillPeerListener listener) throws NoBootstrapConfiguredException {
    int peerRequired = Integer.parseInt(configFile.getProperty(REQ_NPEER, REQ_NPEER_DEFAULT));
    System.out.println("peer richiesti " + peerRequired);
    //      final String name = this.getPeerDescriptor().getName();
    BootstrapClientBehavior bcb = new BootstrapClientBehavior(this, peerRequired);
    bcb.addFullFillPeerListener(listener);

    Thread thread = new Thread(bcb);
    thread.run();
}

From source file:net.dries007.holoInventory.client.ClientHandler.java

public void init() {
    MinecraftForge.EVENT_BUS.register(Renderer.INSTANCE);

    MinecraftForge.EVENT_BUS.register(KEY_MANAGER);

    if (HoloInventory.getConfig().doVersionCheck) {
        Thread vc = new Thread(VERSION_CHECK);
        vc.setDaemon(true);//  ww w.j  a  va 2 s  . c o m
        vc.setName(Data.MODID + "VersionCheckThread");
        vc.run();

        MinecraftForge.EVENT_BUS.register(this);
    }
}