Java Threading: Concepts and Principles

Source: Internet
Author: User

A thread is a thread in a program that executes.A Java Virtual machine allows an application to run multiple execution threads at the same time.
Each thread has a priority.A thread with a higher priority takes precedence over a thread's lower priority execution.Each thread may or may not also be marked as a daemon.When code running in a thread creates a new thread object, the priority of the new thread is initially set to the priority of the creation thread, and is the daemon thread when and only if the creation thread is the daemon.When a Java virtual machine is started, it usually has a single non-daemon thread (it usually calls a method called the primary specified class).The Java Virtual machine continues until any of the following conditions occur when the thread executes:The exit method of the runtime class has been called and the security Manager allows the exit operation to occur.None of the threads have been killed by a daemon thread, either by calling the Run method or by throwing an exception that propagates beyond the run method.
There are two ways to create a new thread of execution.One is to declare a subclass of a class thread.This subclass should override the run method of the thread class.Instances of subclasses can be assigned and started. The other is to inherit the Runnable interface,The runnable interface should be implemented by any class whose instance is intended to be executed by a thread. This class must define the arguments that are called to run the method . This interfaceDesigned for public protocols that execute code objects when they want to be activated. For example, therunnable interface is implemented by the thread class . Being activated simply means that a thread has started and has not stopped. In addition, therunnable interface provides a class of means that are active rather than inheriting threads . that is , implementing runnable can not instantiate a thread instance, and run the class as the target inheritance threads itself. in most cases , therunnable interface should be used if you only intend to override the run () method, and there are no other threading methods.

Java Threading: Concepts and Principles

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.