Java Foundation Eighth Day Lectures Summary (2)--Multithreading &thread

Source: Internet
Author: User

Process

To view a process in Task Manager, the application corresponds to a process

Memory between processes is isolated, inter-process is socket communication through sockets


What is a thread?

------------------------------

Threads are code snippets that execute concurrently during program execution

Threads are capable of sharing memory.

The execution of the thread is performed from top to bottom in order.

Create thread mode One

Inherit thread

  1. The Run method in the subclass overlay that stores the code executed by the thread in run

  2. The same thread that creates the subclass object is also created.

  3. To open a thread by calling the Start method

    Thread is the threading class start ()//notification CPU can start executing the purebred

    Run ()//thread specifically executes the code snippet.

    Thread t=new thread ();

    T.start ();


  4. Package com.test0516;


  5. Class MyThread {


  6. public static void Main (string[] args) {

  7. MyThread1 t1=new MyThread1 ();

  8. T1.start ();

  9. System.out.println ("============");

  10. New Thread () {

  11. public void Run () {

  12. System.out.println ("2nd thred");

  13. }

  14. }.start ();

  15. Thread T2=new thread () {


  16. @Override

  17. public void Run () {

  18. System.out.println ("2nd thradaaaaaa============");

  19. System.out.println (Thread.CurrentThread (). GetName () + "current T2 thread");

  20. }

  21. };

  22. T2.start ();

  23. System.out.println (T2.getname () + "WY");

  24. System.out.println (Thread.CurrentThread (). GetName () + "Current thread");

  25. }

  26. }

  27. Class MyThread1 extends thread{

  28. public void Run () {

  29. System.out.println ("Run ...");

  30. }

  31. }

Java Foundation Eighth Day Lectures Summary (2)--Multithreading &thread

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.