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(ThreadGroup group, Runnable target, String name) 

Source Link

Document

Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group .

Usage

From source file:io.s4.zeno.SiteTest.java

public static void main(String[] arg) throws JSONException, KeeperException, IOException, InterruptedException {

    PropertyConfigurator.configure("log4j.properties");

    String name = arg[0];/* w ww .j  ava  2 s . c  o  m*/
    String zkaddr = arg[1];
    String zkbase = arg[2];
    String specStr = arg[3];

    ConfigMap spec = new JSONConfigMap(specStr);

    ZooKeeper zk = new ZooKeeper(zkaddr, 3000, zkhandler);
    zookeeper = new ZooKeeperHelper(zk, 5, 5000);
    zkpath = new ZKPaths(zkbase);

    ZooKeeperInfo zkinfo = new ZooKeeperInfo();
    zkinfo.zookeeper = zookeeper;
    zkinfo.zkpath = zkpath;
    zkinfo.taskHolder = new NonblockingLockset(zookeeper, zkpath.taskBase);
    zkinfo.partsHolder = new NonblockingLockset(zookeeper, zkpath.partsBase);
    zkinfo.standbySequence = new DistributedSequence(zookeeper, zkpath.standbyBase);

    final Site site = new Site(name, spec);

    ZKCluster cluster = new ZKCluster(zookeeper, zkpath);
    ZKJobList jobList = new ZKJobList(site, zkinfo);
    ZKPartList partList = new ZKPartList(site, zkinfo);
    SiteInitializer init = new SiteInitializer();

    site.setCluster(cluster);
    site.setJobList(jobList);
    site.setPartList(partList);
    site.setInitializer(init);

    class ZenoThreadGroup extends ThreadGroup {
        public ZenoThreadGroup() {
            super("ZenoThreadGroup");
        }

        public void uncaughtException(Thread t, Throwable e) {
            System.out.println("ZENOTHREADGROUP CAUGHT AND EXCEPTION FROM THREAD " + t
                    + ". SO EXITING. DETAILS:" + e + "\nCAUSED BY: " + e.getCause() + "\n");
            e.printStackTrace();

            System.exit(1);
        }
    }

    Thread t = new Thread(new ZenoThreadGroup(), new Runnable() {
        public void run() {
            site.start();
        }
    }, "zenorunthread");
    t.start();

    System.out.println();

    t.join();
}