Example usage for java.lang Thread Thread

List of usage examples for java.lang Thread Thread

Introduction

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

Prototype

public Thread(String name) 

Source Link

Document

Allocates a new Thread object.

Usage

From source file:com.sm.replica.TestRClient.java

public static void main(String[] args) {
    int i = 10;//from  w  w  w .  j a  v a 2 s.  c om
    List<String> list = new ArrayList<String>(i);
    for (int j = 0; j < i; j++)
        list.add(null);
    logger.info("freq " + list.size());

    String logPath = "/Users/mhsieh/java/open/voldemort-0.81/config/addon-1/data/log";
    String store = "test";
    CacheStore trxLog = new CacheStore(logPath, null, 0, store, false);
    ReplicaClient client = new NTReplicaClient("localhost:6910", store, trxLog, logPath);
    new Thread(client).start();
}

From source file:trendulo.ingest.Ingest.java

/**
 * @param args/*from w  w w. ja v  a2s  . co m*/
 */
public static void main(String[] args) {

    final Logger log = Logger.getLogger(Ingest.class);

    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

    // Start the N-Gram Source
    final TemporalNGramSource nGramSource = (TemporalNGramSource) context.getBean("nGramSource");
    Thread nGramSourceThread = new Thread(nGramSource);
    nGramSourceThread.start();

    // Start the N-Gram Ingester that will take from the source
    final TemporalNGramIngester nGramIngester = (TemporalNGramIngester) context.getBean("nGramIngester");
    Thread nGramIngesterThread = new Thread(nGramIngester);
    nGramIngesterThread.start();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            log.info("Shutting Down Ingest...");
            nGramSource.shutdown();
            nGramIngester.shutdown();
        }
    });
}

From source file:Producer.java

public static void main(String[] args) {
    BlockingDeque<Integer> deque = new LinkedBlockingDeque<Integer>(5);
    Runnable producer = new Producer("Producer", deque);
    Runnable consumer = new Consumer("Consumer", deque);
    new Thread(producer).start();
    try {/*from   w ww .  j  a  v a2 s.  co  m*/
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    new Thread(consumer).start();
}

From source file:ThreadedEchoServer.java

public static void main(String[] args) {
    try {/*w  ww . j a  v a 2  s . c o m*/
        int i = 1;
        ServerSocket s = new ServerSocket(8189);

        while (true) {
            Socket incoming = s.accept();
            System.out.println("Spawning " + i);
            Runnable r = new ThreadedEchoHandler(incoming);
            Thread t = new Thread(r);
            t.start();
            i++;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.apress.prospringintegration.channels.rendezvouschannel.Main.java

public static void main(String[] args) throws Throwable {
    String contextName = "rendezvous-channel.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();//  www . j  a v a 2s.co m

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketReceiver ticketReceiver = applicationContext.getBean(TicketReceiver.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);

    // start *before* message publication because it'll block on put
    Thread consumerThread = new Thread(ticketReceiver);
    consumerThread.start();

    List<Ticket> tickets = ticketGenerator.createTickets();
    for (Ticket ticket : tickets) {
        problemReporter.openTicket(ticket);
    }
}

From source file:net.socket.bio.TimeServer.java

/**
 * @param args/*w  w w  .j  a va  2s  .co  m*/
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    int port = 8089;
    if (args != null && args.length > 0) {

        try {
            port = Integer.valueOf(args[0]);
        } catch (NumberFormatException e) {
            // 
        }

    }
    ServerSocket server = null;
    try {
        server = new ServerSocket(port);
        System.out.println("The time server is start in port : " + port);
        Socket socket = null;
        while (true) {
            socket = server.accept();
            System.out.println("socket name" + socket);
            new Thread(new TimeServerHandler(socket)).start();
        }
    } finally {
        IOUtils.closeQuietly(server);
    }
}

From source file:com.apress.prospringintegration.corespring.iocbasics.BasicThreadColorRunnable.java

public static void main(String[] args) throws Exception {
    ApplicationContext app = new ClassPathXmlApplicationContext("ioc_basics.xml");
    ColorEnum threadColor = app.getBean("threadColor", ColorEnum.class);
    System.out.println("Parent thread color: " + threadColor);

    BasicThreadColorRunnable dcr = new BasicThreadColorRunnable(app);
    new Thread(dcr).start();
}

From source file:com.sourcethought.simpledaemon.EchoTask.java

public static void main(String[] args) throws Exception {
    // setup command line options
    Options options = new Options();
    options.addOption("h", "help", false, "print this help screen");

    // read command line options
    CommandLineParser parser = new PosixParser();
    try {/*from   w ww .  j a  v  a 2  s  .  c o  m*/
        CommandLine cmdline = parser.parse(options, args);

        if (cmdline.hasOption("help") || cmdline.hasOption("h")) {
            System.out.println("SimpleDaemon Version " + Main.version);

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(
                    "java -cp lib/*:target/SimpleDaemon-1.0-SNAPSHOT.jar com.sourcethought.simpledaemon.Main",
                    options);
            return;
        }

        final SimpleDaemon daemon = new SimpleDaemon();
        daemon.start();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                if (daemon.isRunning()) {
                    try {
                        System.out.println("Shutting down daemon...");
                        daemon.stop();
                    } catch (Exception ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }));

    } catch (ParseException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.github.liyp.test.TestMain.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // add a shutdown hook to stop the server
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override//w ww  .ja v  a  2s. c  o  m
        public void run() {
            System.out.println("########### shoutdown begin....");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("########### shoutdown end....");
        }
    }));

    System.out.println(args.length);
    Iterator<String> iterator1 = IteratorUtils
            .arrayIterator(new String[] { "one", "two", "three", "11", "22", "AB" });
    Iterator<String> iterator2 = IteratorUtils.arrayIterator(new String[] { "a", "b", "c", "33", "ab", "aB" });

    Iterator<String> chainedIter = IteratorUtils.chainedIterator(iterator1, iterator2);

    System.out.println("==================");

    Iterator<String> iter = IteratorUtils.filteredIterator(chainedIter, new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            System.out.println("xx:" + arg0.toString());
            String str = (String) arg0;
            return str.matches("([a-z]|[A-Z]){2}");
        }
    });
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }

    System.out.println("===================");

    System.out.println("asas".matches("[a-z]{4}"));

    System.out.println("Y".equals(null));

    System.out.println(String.format("%02d", 1000L));

    System.out.println(ArrayUtils.toString(splitAndTrim(" 11, 21,12 ,", ",")));

    System.out.println(new ArrayList<String>().toString());

    JSONObject json = new JSONObject("{\"keynull\":null}");
    json.put("bool", false);
    json.put("keya", "as");
    json.put("key2", 2212222222222222222L);
    System.out.println(json);
    System.out.println(json.get("keynull").equals(null));

    String a = String.format("{\"id\":%d,\"method\":\"testCrossSync\"," + "\"circle\":%d},\"isEnd\":true", 1,
            1);
    System.out.println(a.getBytes().length);

    System.out.println(new String[] { "a", "b" });

    System.out.println(new JSONArray("[\"aa\",\"\"]"));

    String data = String.format("%9d %s", 1, RandomStringUtils.randomAlphanumeric(10));
    System.out.println(data.getBytes().length);

    System.out.println(ArrayUtils.toString("1|2| 3|  333||| 3".split("\\|")));

    JSONObject j1 = new JSONObject("{\"a\":\"11111\"}");
    JSONObject j2 = new JSONObject(j1.toString());
    j2.put("b", "22222");
    System.out.println(j1 + " | " + j2);

    System.out.println("======================");

    String regex = "\\d+(\\-\\d+){2} \\d+(:\\d+){2}";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher("2015-12-28 15:46:14  _NC250_MD:motion de\n");
    String eventDate = matcher.find() ? matcher.group() : "";

    System.out.println(eventDate);
}

From source file:com.apress.prospringintegration.channels.messagingtemplate.Main.java

public static void main(String[] args) {
    String contextName = "messaging-template.xml";

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(contextName);
    applicationContext.start();/*from   ww w .  j  a  v a2  s .  c  om*/

    ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class);
    TicketReceiver ticketReceiver = applicationContext.getBean(TicketReceiver.class);
    TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class);

    List<Ticket> tickets = ticketGenerator.createTickets();
    for (Ticket ticket : tickets) {
        problemReporter.openTicket(ticket);
    }

    Thread consumerThread = new Thread(ticketReceiver);
    consumerThread.start();
}