Start thread with start Instead of using run Method

public static void main(String[] args) {
Thread t=new Thread("Thread-TEST"){
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
};
t.start();
// t.run();
}

start Method will call start0 Method ,start0 yes native Method , Will start a thread , The virtual machine calls the thread run Method , Here, because of overriding the run Method , So call the subclass of run Method

use start Start thread , Print is

Indicates that a new thread has been created , The thread name is Thread-TEST

use run When the method is used

At this time , Is executed directly in the main thread , No thread created , It's just a call to the object's method , Because there is no call to start0 Local method

Start thread with start More articles on methods

  1. Why the startup thread is start Method ?

    Why the startup thread is start Method Ten years have seen the spring and autumn come , One hundred years can prove birth, aging and death , A thousand years of lamentable Dynasty change , The stars change in ten thousand years .   If mortals use the vision of a day , To explore the world for millions of years , Is it like a frog in a well ? background : The startup thread is start ...

  2. C# Add three threads to start executing a method at the same time , And call a method in turn in the loop print output .

    Add three threads to start executing a method at the same time , And call the print input in a method in turn :ABC ABC ABC ABC The implementation code is as follows : using System; using System.Collections.Generi ...

  3. Java in Thread Method to start the thread

    public class ThreadTest extends Thread {  private int count = 10; @Override public void run() { // rewrite ...

  4. Struts+Spring+Hibernate The startup thread of the project

    stay Java Web In the project , It is often necessary to start a thread at the beginning of a project , Run code at regular intervals , For example, scan the changes in the database and so on . To implement this function , Can now web.xml Define a Listener, And then here ...

  5. my Android Best practice —— Android How to realize the startup screen

    This article gives an example of Android How to realize the startup screen . Share with you for your reference . The specific analysis is as follows : The startup screen is often used in applications , A background thread will be started to prepare the running resources of the main program .Android To achieve the startup screen, you can do this : ...

  6. Thread implementation methods and differences extends Thread、implements Runable

    /** Thread exists in the process , Processes are created by the system . There are two ways to create a new thread of execution Be careful :   Thread replication run Method , And then use start() Method call , It's actually called run() Method , It's just that if you start it directly run() Method , ...

  7. java Threads — Create and start threads

    Create and start threads , Tradition has two ways : The way 1: Inherit Thread class : The way 2: Realization Runnable Interface : Thread class (java.lang.Thread):Thread Classes and Thread A subclass of can be called a thread class . read ...

  8. java The guard thread of multithreading and Join Method

    Copyright notice : This article is from Wang Lei's blog , Please indicate the source of reprint . One . Overview and examples of daemons A guard thread is a thread that provides " guardian " effect , To put it bluntly, it serves other threads , such as GC Threads . java Threads in the program are divided into ...

  9. 【Java Language 】Java Multithreading One ( Thread start | Thread the interrupt )

    One . Thread start Thread start : -- 1. Inherit Thread Running threads : rewrite Thread Class run Method , Then execute the thread ; -- 2. Realization Runnable Interface , And run the thread ; -- ...

Random recommendation

  1. AngularJS Actual combat

    I've been studying for so many days AngularJS, Today, I want to share a simple Demo-- User query system , To consolidate what we have learned before . Functional requirements need to meet two points 1. Query all user information , And show it on the front end 2. according to id Query user's letter ...

  2. markdown Editor

    After some exploration, we finally found two that can be previewed in real time markdown Editor One ,sublime text 3 + MarkDown Editing + OmniMarkupPreviwer Installation methods are available on the Internet , Here ...

  3. A Xu's php development environment

    Over the years ,php Technology is changing with each passing day , There are many changes . For developers , It feels like there are some simple ways , Write it down , For future use . I think so. ,Linux Write php Not as good as windows Write php, debugging , Information and various functions are comprehensive , and lin ...

  4. sqlite stay Android On the one bug:SQLiteCantOpenDatabaseException when nativeExecuteForCursorWindow

    See more here https://ahangchen.gitbooks.io/windy-afternoon/content/ ::-/com.company.product W/System.er ...

  5. PE File structure ( Four ) Output table

    PE File structure ( Four ) Refer to book :< encryption and decryption > video : Little turtle Decryption series video Output table In general, output tables exist in dll in . The output table provides The names of the functions in the file and the addresses of these functions , PE The loader changes by outputting the table ...

  6. C# Relative path to absolute path

    If it's a path, it's a relative path , Use Path transformation System.IO.Path.Combine( Folder , relativePath); A folder is a relative folder . In this way, the relative path can be turned to absolute . See :http: ...

  7. ACM Everybody loved them A^B

    seek A^B An integer represented by the last three digits of .  explain :A^B The meaning is "A Of B Power "  Input Input data contains multiple test instances , Each instance takes up one line , By two positive integers A and B form (1<=A,B<=10 ...

  8. CentOS7+CDH5.14.0 Record of the whole installation process , Picture and text explain the whole process of measurement -3 Disable swapping and disable large pages

    1. No exchange ( Every machine has to do ): Carry out orders :vim /etc/sysctl.conf Add a row :vm.swappiness=0 Carry out orders :sudo sysctl vm.swappiness=0 2. Forbid ...

  9. element upload Upload multiple images at once ( Including custom upload does not go action)

    The most important ones are circled

  10. bzoj The thousand questions project 127:bzoj1041: [HAOI2008] The whole point on the circle

    http://www.lydsy.com/JudgeOnline/problem.php?id=1041 set up X>0 ,Y>0 X^2 + Y^2 = R^2 X^2 = R^2-Y^2 ...