Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


java how to use thread join using -'java,concurrency,join,multithreading'


java how to use thread join  using -'java,concurrency,join,multithreading'

I'm new to threads. How can I get t.join to work, whereby the thread calling it waits until t is done executing?

This code would just freeze the program, because the thread is waiting for itself to die, right?

public static void main(String[] args) throws InterruptedException {
    Thread t0 = new Thready();
    t0.start();

}

@Override
public void run() {
    for (String s : info) {
        try {
            join();
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.printf("%s %s%n", getName(), s);
    }   
}


What would I do if I wanted to have two threads, one of which prints out half the info array, then waits for the other to finish before doing the rest?
    

asked Sep 7, 2015 by rajesh
0 votes
5 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...