Java thread (2) implementation

Source: Internet
Author: User

There are two ways to implement Java threads:Inherit thread,Runnable.

 
Package COM. ch. thread; public class threadtest extends thread {public threadtest (string name) {super (name); // todo auto-generated constructor stub} @ overridepublic void run () {// todo auto-generated method stubsuper. run (); For (INT I = 0; I <100; I ++) {system. out. println (this. getname () + "thread running ing,") ;}/ *** @ Param ARGs * @ throws interruptedexception */public static void main (string [] ARGs) throws interruptedexception {// todo auto-generated method stubthreadtest TT = new threadtest ("thread one"); threadtest TT2 = new threadtest ("Thread two"); TT. start (); // TT. join (); tt2.start ();}}
 package COM. ch. thread; public class threadimpl implements runnable {@ overridepublic void run () {// todo auto-generated method stubsystem. out. println ("thread running,");}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubthreadimpl Ti = new threadimpl (); thread TT = new thread (Ti); TT. start () ;}

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.