Multithreaded Programming:A running program is often called a process , and each task is called a thread , and a program that runs multiple threads within a program is called a multithreaded procedure.The difference between threads and processes: ①
Control of the thread:Threading Support in Java provides some handy tools to better control the execution of threads through these handy ways of working. One, join thread:Thread provides a way for a thread to wait for another thread to
Thread basics: thread (4) -- basic thread operations in JAVA (below)2-2. interrupt Signal
Interrupt, the meaning of the word itself is to interrupt, terminate, block. When a thread receives this signal (command), it sets the self-generated status
I believe everyone is familiar with the object-oriented three feature encapsulation, inheritance, polymorphism, everyone can say one or two sentences, but most of them just know what these are, do not know how the CLR is implemented internally, so
What is timeunit?
Timeunit is Java. util. A class in the concurrent package. timeunit provides a thread pause operation with better readability, which is usually used to replace the thread. sleep (), for a long time, the thread's sleep () method
3. thread status
There are multiple states in the thread, including new status, available status, running status, waiting/blocked/sleeping/monitoring/suspended status, and dead status 5.
1) New status
The new State refers to the state in which the
Methods for stopping thread execution in JavaMethods for stopping thread execution in JavaI. Theory of suspending or stopping a threadIn Java programming, there are several methods to pause or stop the currently running thread. Thread. Sleep () is
One, thread safetyWhen multiple threads execute the same piece of code, each execution result is the same as the result of single-threaded execution, and there is no two semantics for the execution result, which can be called thread-safe.When it
1. What is the difference between int and integer?A: Java is a nearly pure object-oriented programming language, but for the convenience of programming or the introduction of basic data types, but in order to be able to use these basic data types as
Thread Sleep
If you need to suspend the currently executing thread for a period of time and enter a blocking state, you can do so by calling the static sleep method of the thread class. Two overloaded forms of the Sleep method:
1.static void sleep
Reprinted from: http://hi.baidu.com/person_space/blog/item/e39cc6c43adfbeaf8326ac43.html
Link: Another good explanation (http://hi.baidu.com/feiyuyitiao/blog/item/af89821e5df88b1941341750.html)
Here we will provide a complete example to illustrate
Basic (III)
Several important methods of thread objects
Although the common methods of thread objects can be learned through the API documentation, there are many methods that are not detailed only from the API description.
I was going to use a
Before you learn the thread class, you will first introduce threading-related knowledge: Several states of a thread, context switches, and then the specific use of the methods in the thread class.The following is the directory outline for this
1. These two methods come from different classes, and the sleep method belongs to the Thread,wait method that belongs to object.2. The most important thing is that the sleep method does not release the lock, and the wait method frees the lock so
I. The state of a threadBefore we formally learn the specific methods in the thread class, let's look at the state of the thread, which will help to understand the methods in the thread class.Threads go through a number of States, from creation to
Reprint Please specify source:http://blog.csdn.net/ns_code/article/details/17091267use interrupt () to break the threadWhen one thread is running, another thread can call the interrupt () method of the corresponding thread object to break it, and
First, the state of the threadBefore we formally learn the specific methods in the thread class, let's look at the state of the thread, which will help to understand the methods in the thread class.Threads go through a number of States, from
Although the common methods of threading objects can be understood through API documentation, there are many ways to understand them simply from API descriptions.Originally intended to use a section of the thread approach to some of the important
V. Sleep and wake up a threadSometimes you will want to run the thread after a certain amount of time. For example, a thread in a program checks the state of the sensor every minute, and the remaining time, the thread should be in an idle state.
It was strange to see the TimeUnit.SECONDS.sleep () method, how does the sleep method also be provided here? Public voidSleepLongTimeoutthrowsinterruptedexception {if(Timeout > 0) { Longms =Tomillis (timeout); intNS =Excessnanos (timeout, MS)
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.