A long time did not write a blog, before work always do not have, but always feel that blogging is a good way to record their own technology process
So after the resignation came to the North Soft, another school, another time to write a blog, so again began to write a blog, hehe, again when the students feel
That's nice!!!!
This is the thread of the Join method, used to always use his run and sleep method, which two is relatively clear, for this join method, his
The main function is that when you call other threads in a method, if you use a similar thread1.join (), then the thread of this call
It started to wait for thread1 this thread to return, when thread1 this thread's Run method runs out of return, this current main thread will continue
Continue to run downward. Of course, join has two parameter methods, which means that first wait for the thread to be called, such as
Thread1.sleep (1000) so that the main thread waits for Thread1 to run until the Thread1 runs out or the current main thread waits for more than 1 seconds will not
The THREAD1 thread continues to execute downward. The code is as follows
Package Com.bird.concursey;import java.util.date;import java.util.concurrent.timeunit;/** * Data source * @author Bird * September 15, 2014 PM 10:10:04 */public class Datasourceloader implements Runnable{public void Run () {System.out.println (" Begining the data source loding "+ new Date ()); try {TimeUnit.SECONDS.sleep (4);} catch (Interruptedexception e) {E.printsta Cktrace ();} System.out.println ("Begining the data source loding" + new Date ());} public static void Main (string[] args) {Datasourceloader dsloader = new Datasourceloader (); Thread thread1 = new Thread (Dsloader, "Dsloader"); Networkconnectionsloader Ncloader = new Networkconnectionsloader (); Thread thread2 = new Thread (Ncloader, "Ncloader"); Thread1.start (); Thread2.start (); try {thread1.join ();//thread2.join (1000);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} System.out.println (New Date ());}}
Package Com.bird.concursey;import Java.util.date;import Java.util.concurrent.timeunit;public class Networkconnectionsloader implements Runnable {public void run () {System.out.println ("begining the data source loding" + NE W Date ()); try {TimeUnit.SECONDS.sleep (6);} catch (Interruptedexception e) {e.printstacktrace ();} System.out.println ("Begining the data source loding" + new Date ());}}
Begining the data source Lodingmon Sep 22:27:41 CST 2014begining the data source Lodingmon Sep 22:27:41 CST 2014begi Ning the data source Lodingmon Sep 22:27:45 CST 2014Mon Sep 22:27:46 CST 2014begining the data source Lodingmon Sep 22:27:47 CST 2014
Introduction to Java Multi-thread---thread.join