Simple use of JAVA threads __java

Source: Internet
Author: User

Package com. JUnit;


/**
* Java Threading Test
* @author RSun
* @Date 2012-10-26 02:12:56
* @Email

*/
public class Test {

public static void Main (string[] args) {


New Testthread (). Start ();
New Testthread ("hehe"). Start ();
New Thread (New Testrunnable ()). Start ();
New Thread (New testrunnable ("haha")). Start ();

The following invocation method does not reach the new thread effect and will always execute the aaaaaa before executing the BBBBBB
New Testrunnable ("Aaaaaa"). Run ();
New Testrunnable ("BBBBBB"). Run ();
SYSTEM.OUT.PRINTLN ("Output order is different every time.") ");


}

}


/** extends way to implement thread **/
Class Testthread extends thread{
Private String S;

Public Testthread () {
}

Public Testthread (String ss) {
THIS.S = SS;
}

@Override
public void Run () {
SYSTEM.ERR.PRINTLN ("Thread Threads start:" + s);
}
}

/** implements mode implementation thread   **/
class Testrunnable implements runnable{
         private String S;
 
        public testrunnable () {
        }
 
        public testrunnable (String ss) {
             THIS.S = SS;
       }

        Override
        ublic void Run () {
               System.err.println ("runnable thread Start:" + s);
       }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.