Java Multithreaded Example

Source: Internet
Author: User

/* Multithreaded example. There are two ways to create multithreading. One inherits the thread class and overwrites the Run method in thread, and calls its Start method. The function of the Startt method is to open the thread and call the Run method. The purpose of the replication run method is to store the custom code in the Run method and let the thread run. */class demo extends thread{    public void run () {         for (int x =0; x <40;x++) {             system.out.println ("Demo run ..." +x);             }        }     }class threaddemo{    public static void main (String []args] {        demo d = new demo ();         d.start ();//Open the thread and execute the thread's Run method. If it is D.run (), then only the Run method is allowed, and no multithreading is turned on.                 for (int i  = 0;i<40;i++) {            system.out.println (" HELLOWOLRD----"+i);            }    The main thread of the  //, executed in parallel with start-open threads.     }}


This article from "Sima" blog, reproduced please contact the author!

Java Multithreaded Example

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.