search
Home类库下载java类库What methods does thread class have?

What methods does thread class have?

Apr 08, 2019 pm 01:42 PM
Thread class

Methods in the Thread class can be divided into instance methods and static methods. Instance methods include start() method, run() method, etc. Static methods include currentThread() method, sleep(long millis) ) methods, etc.

What methods does thread class have?

[Recommended course: Java Tutorial]

in the Thread class Instance method

start() method

The function of this method is to notify the thread planner that the scene can be run. It should be noted that the order in which the start method is called does not represent the order in which threads are started, that is, the CPU executes the code of which thread is uncertain.

run() method

This method is executed after the thread class calls start. If you call run directly instead of the start method, it will be the same as the ordinary method. The difference

isAlive() method

is to determine whether the current thread is active. The active status means that it has been started but not terminated.

getPriority() and setPriority(int newPriority) methods

These two methods are used to get and set the priority of the current thread. Threads with higher priority get more CPU. In other words, among the two waiting threads, the thread with higher priority is easier to be executed by the CPU. By default, the thread's priority is 5. The priority of threads is divided into levels from 1 to 10.

isDaeMon, setDaemon(boolean on) method

There are two types of java threads, one is the user thread and the other is the daemon thread. The daemon thread is a special thread. Any daemon thread is the nanny of all non-daemon threads in the jvm. When there are no non-daemon threads in the process, the daemon thread will be automatically destroyed. A typical daemon thread is a garbage collection thread.

The first method is to determine whether the thread is a daemon thread. The second method is to set the thread as a daemon thread. It must be setDaemon(true) before the thread starts

interrupt() Method

Using this method will not interrupt the thread. In fact, the actual function of calling interrupt is to throw an interrupt signal when the thread is blocked, so that the thread can exit the blocked state.

join() method

The join method will cause the thread calling the join method to block indefinitely until the thread calling the join method is destroyed. The join method uses wait internally. (), so the lock will be released.

Static method of Thread class

currentThread() method

This method returns a reference to the currently executing thread object .

sleep(long millis) method

The function of the sleep method is to sleep the executing thread at the specified time. The lock is not released.

yield() method

Pauses the currently executing thread object and executes other threads. This pause will give up cpu resources, and the time of giving up is uncertain

Method calling method in Thread class

When calling the method in Thread, in the thread class, There are two methods:

this.xxx() method

The thread in this method is the thread instance itself

Thread.currentThread .xxx() or Thread.xxx() mode

This indicates the thread executing the code block where Thread.currenThread.xxx() is located.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone.

The above is the detailed content of What methods does thread class have?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!