Thread run, start, Threadrunstart
Class TestThread extends Thread {
Public void run (){For (int I = 0; I System. out. println (Thread. currentThread (). getName () + "--- is running ");}}}Public class Thread01 {Public static void main (String [] args ){TestThread tt1 = new TestThread ();TestThread tt2 = new TestThread
First, know the thread of start () and run ()
1. Start ():
Let's take a look at the introduction of this method in the API:
Causes the thread to start executing, and the Java virtual machine invokes the thread's run method.
The result is two threads runn
The interview may be asked why we execute the run () method when we call the start () method, why can't we call the Run () method directly?
Java Methods for creating threadsIn fact, the most important thing to create a thread is to provide the thread function (the callback function), which acts as the entry function for the newly created
The start () method is called on the tread object of the thread instead of run () or another method.Before invoking the Start method, the thread is in the new state and the new State refers to having a thread object! But there is not a real thread.A series of complex things
is created. You can specify two values:create_suspended: After the thread is created, it is in a pending state until the call: ResumeThread0: When the thread is created, it starts running.Lpsecurityattrs: Point to a security_attributes structure that flags the security of the newly created thread. If NULL,Then the newly created
MFC-based writing thread Quick StartProgramMember's house Author: Unknown Date: 19:19:00
--------------------------------------------------------------------------------For beginners, I don't know where to start writing threads or what to do with writing threads. Below is a brief framework of a thread.
//////////////////////////////////////// ////////////////
The difference between start () and run () in threadstart () : Its role is to start a new thread, and the new thread executes the corresponding run () method. Start () cannot be called repeatedly. Run () : Run () is the same as the normal member method and can be called rep
First step: Build the Thread class and start the thread1 /**2 * "1" implements the Runnable interface, overriding the Run method. 3 * The logic code inside the "2" Run method is the thread body4 * "3" creates an object of the thread class5 * "4" creates a proxy object for the threa
Both of these methods can start thread activity, but their differences are similar to the difference between start () and run () in the Java thread class.
First look at the Official document description:
Translation is:
Start () method
There are three ways to create threads: one is to inherit the thread class, the other is to implement the Runnable interface, and the third is to create threads using callable and future.Inheriting the thread class to create threads Steps:
Defines the thread subclass and overrides the run method of the class, which represents the task to be completed, t
Creation and initiation of threads
The Java language has built-in multithreaded support, and all classes that implement the Runnable interface can be started with a new thread that executes the run () method of the instance, and the thread ends when the run () method finishes executing. Once a thread has finished executing, the instance can no longer be restarte
I used thread in my work. I started with an error and studied it carefully for a moment.
Preface: Today I wrote code like this.
new Thread() { @Overridepublic void run() {System.out.println("test");} }.run();
In this way, a new thread execution is started, but after printing the thread information, it is still found
The thread class contains the start () and run () methods, what are the differences? This chapter will provide an answer to this. The contents of this chapter include:Description of the difference between start () and run ()Example of the difference between start () and run ()Start
Q: one. NET how many threads did the program start at run time?
Answer: at least 3.
1. Start CLR and run main thread of Main method2. Debugger Help Thread3.Finalizer Threads
Copy Code code as follows:
Class Program
{
static void Main (string[] args)
{
Console.WriteLine ("Main thread: {0}",
THREAD.CURREN
The reason why a thread occurs is to make better use of the CPU and make her work more "savvy.
Start a thread by calling the START () method of the thread class. The thread is in the ready state and is not running.
This
1.start () method to start a thread, which really implements multithreading, without waiting for the Run method body code to complete and proceed directly to the following code:
Start a thread by invoking the start () method of th
to bring the thread-safe, heheThe protagonist has set, of course, is the script, we need to set the time for the protagonist to play, here I use the servlet to start the thread, specifically as followsPackage Com.smartsoft.thread;import Java.util.map;public class Servicethreadmap {mapPackage Com.smartsoft.servlet;import Java.util.iterator;import Javax.servlet.se
C++11 introduces a new line threading that includes tools to start and manage threads, and provides a way to synchronize (mutex, lock, and atomic variables), and I will try to introduce you to this new line threading.
If you want to compile the code in this article, you need at least one compiler that supports C++11, I'm using GCC 4.6.1, and I need to use-c++0x or-c++11 parameters to enable c++11 support.
Start
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.