Example usage for java.lang Thread start

List of usage examples for java.lang Thread start

Introduction

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

Prototype

public synchronized void start() 

Source Link

Document

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Usage

From source file:Main.java

public ThreadGroupDemo() {
    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();//  www .  j  a  v  a  2s. c  o m

    ThreadGroup[] grpList = new ThreadGroup[pGroup.activeGroupCount()];
    int count = pGroup.enumerate(grpList, true);
    for (int i = 0; i < count; i++) {
        System.out.println("ThreadGroup" + grpList[i].getName() + " found");
    }
}

From source file:Main.java

public ThreadGroupDemo() {

    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
    pGroup.setDaemon(true);//from ww w .  j a v  a 2  s .  c  o m

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");
    cGroup.setDaemon(true);

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("Is " + pGroup.getName() + " a daemon ThreadGroup? " + pGroup.isDaemon());
    System.out.println("Is " + cGroup.getName() + " a daemon ThreadGroup? " + cGroup.isDaemon());

}

From source file:Main.java

public ThreadGroupDemo() {
    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();//from   w  w w. j  av a  2  s.co  m

    Thread[] list = new Thread[pGroup.activeCount()];
    int count = pGroup.enumerate(list, true);
    for (int i = 0; i < count; i++) {
        System.out.println("Thread " + list[i].getName() + " found");
    }

}

From source file:Main.java

public ThreadGroupDemo() {
    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();/*  w  ww. ja v  a  2s . c o m*/

    System.out.println("Listing parentThreadGroup: " + pGroup.getName());
    pGroup.list();

    System.out.println("Listing childThreadGroup : " + cGroup.getName());
    cGroup.list();

}

From source file:Main.java

public ThreadGroupDemo() {
    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();//  w ww. j a v  a 2s  . c  om

    // determine which ThreadGroup is parent
    boolean isParent = pGroup.parentOf(cGroup);
    System.out.println(pGroup.getName() + " is the parent of " + cGroup.getName() + "? " + isParent);

    isParent = cGroup.parentOf(pGroup);
    System.out.println(cGroup.getName() + " is the parent of " + pGroup.getName() + "? " + isParent);

}

From source file:com.android.feedmeandroid.HTTPClient.java

public static Bitmap downloadFile(final String fileUrl) {
    final Bitmap[] bitmap = new Bitmap[1];
    Thread t = new Thread(new Runnable() {
        public void run() {
            URL myFileUrl = null;
            try {
                myFileUrl = new URL(fileUrl);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();//from   w w w  . j  a va2s  .co  m
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                InputStream is = conn.getInputStream();

                Bitmap bmImg = BitmapFactory.decodeStream(is);
                bitmap[0] = bmImg;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    t.start();
    try {
        t.join();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return bitmap[0];
}

From source file:Main.java

public ThreadGroupDemo() {

    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();/*from  w w  w.  ja v a  2s . c  o  m*/

    Thread[] list = new Thread[pGroup.activeCount()];
    int count = pGroup.enumerate(list);
    for (int i = 0; i < count; i++) {
        System.out.println("Thread " + list[i].getName() + " found");
    }

}

From source file:com.bringcommunications.etherpay.Payment_Processor.java

public static void refresh_balance(Payment_Processor_Client client, Context context) {
    if (payment_processor == null) {
        payment_processor = new Payment_Processor(context);
        Thread thread = new Thread(payment_processor);
        thread.start();
    }/*from   w  ww  .ja va2  s .  c  o m*/
    Payment_Message message = new Payment_Message(client, context, "", "", 0, 0, null, false);
    payment_processor.queue_message(message, Message_Type.BALANCE);
}

From source file:com.mobilewallet.services.ForgotPasswordService.java

@GET
@Produces(MediaType.APPLICATION_JSON)//  w ww  .  j  a  v a 2s .com
public Object sendPassword(@Context HttpServletRequest request, @QueryParam("email") String email) {
    log.info("Forgot Password Email : " + email);

    try {
        ForgotPasswordEmailThread sv = new ForgotPasswordEmailThread(email.toLowerCase(),
                request.getRemoteAddr());
        Thread t = new Thread(sv);
        t.start();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    JSONObject obj = new JSONObject();
    try {
        obj.put("sent", true);
    } catch (Exception ex) {

    }
    return obj.toString();
}

From source file:com.bringcommunications.etherpay.Payment_Processor.java

public static void send(Payment_Processor_Client client, Context context, String client_data, String to_addr,
        long size_wei, long gas_limit, byte data[], boolean want_raw_tx) {
    if (payment_processor == null) {
        payment_processor = new Payment_Processor(context);
        Thread thread = new Thread(payment_processor);
        thread.start();
    }//from w ww.j a  va2 s  . co  m
    Payment_Message message = new Payment_Message(client, context, client_data, to_addr, size_wei, gas_limit,
            data, want_raw_tx);
    payment_processor.queue_message(message, Message_Type.SEND);
}