Java Threads and Java modifiers

Source: Internet
Author: User
Tags modifiers thread class volatile

META tags

A property used to describe a document in an HTML Web page.

Meaning: elements provide meta-information about the relevant page.

The <meta> element provides meta-information about the page (meta-information), such as descriptions and keywords for search engines and update frequency.

The <meta> tag is located in the header of the document and does not contain any content. The properties of the <meta> tag define the name/value pairs associated with the document.

Meta is an accessible tag in the head area of the HTML language. In almost all pages, we can see HTML code similar to the following:

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>

1. Properties:

The name attribute is mainly used to describe the Web page, and its corresponding property value is content,content content is mainly convenient for search engine robot to find information and classification information.

The Name property syntax format for the META tag is: parameter "content=" for the specific parameter value ">;.

Where the name attribute mainly has the following parameters:

A,Keywords(keywords)

Description: Keywords is used to tell search engines what keywords are on your page.

Example:

B,description(website content description)

Description: Description is used to tell search engines the main content of your website.

Design highlights of the website content description (description):

① Web pages are described as natural languages rather than listed keywords (contrary to keywords design);

② as accurately as possible to describe the core content of the Web page, usually a summary of the content of the Web page information, that is, the search engine in the search results to display the summary information;

③ page description contains valid keywords;

④ the content of Web page description is highly correlated with the content of page title;

The content of ⑤ Web page description is highly correlated with the main content of Web page.

⑥ page description of the text do not need too much, generally not more than the search engine results summary information of the maximum number of words (usually within 100 text, different search engine slightly difference).

Example: <meta name= "description" content= "This page is about the meaning of science,education,culture." >

C,Robots(Robot Wizard)

Description: Robots is used to tell the search robot which pages need to be indexed and which pages do not.

The content parameters are all,none,index,noindex,follow,nofollow. The default is all.

Example: <meta name= "Robots" content= "None" >

D,author(author)

Description: The author of the callout page

http-equiv , as the name implies, is equivalent to the file header of HTTP, which can send back some useful information to the browser to help correct and accurately display the content of the Web page, the corresponding property value is content, Content is actually the variable value of each parameter.

The Http-equiv property syntax format for the META tag is:; Where the Http-equiv property has the following main parameters:

A,Expires(term)

Description: Can be used to set the expiration time of a Web page. Once the page expires, it must be retransmitted to the server.

Usage: <meta http-equiv= "Expires" content= "fri,12 Jan 2001 18:18:18 GMT" >

Note: The time format of GMT must be used.

B,Pragma(cache mode)

Description: Prevents the browser from accessing page content from the local computer's cache.

Usage: <meta http-equiv= "Pragma" content= "No-cache" >

Note: This setting makes it impossible for visitors to browse offline.

C,Refresh (refreshed)

Description: Automatically refreshes and points to the new page.

Usage: <meta http-equiv= "Refresh" content= "2; URL ">; (note the following quotation marks, respectively, before the number of seconds and after the URL)

Note: 2 of these are meant to be automatically refreshed to URL URLs after 2 seconds of stay.

D,Set-cookie(Cookie setting)

Note: If the page expires, the cookie will be deleted.

Usage: <meta http-equiv= "Set-cookie" content= "COOKIEVALUE=XXX; expires=friday,12-jan-2001 18:18:18 GMT; path=/">

Note: The time format of GMT must be used.

E,window-target(display window settings)

Description: Forces the page to appear on a separate page in the current window.

Usage: <meta http-equiv= "Window-target" content= "_top" >

Note: Used to prevent others from calling their own pages in the frame.

F,Content-type(setting of the display character set)

Description: Sets the character set used by the page.

Usage: <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">

G,content-language(display language Settings)

Usage: <meta http-equiv= "Content-language" content= "ZH-CN"/>

2. Function:

One of the most important features of META tags is to set up keywords to help your homepage be logged in by major search engines, increasing the amount of site visits.

Modifiers in Java

  


Class Internal package sub-class other public allow allow allowed allowed
Protected allow allow       not allowed
Default allow allow not allow private allow not allow disallow not allowed


1. Public

Working with objects: classes, interfaces, members

Description: The class (interface, member) is accessible regardless of the package definition in which it is located

2, Protected

Working with objects: members

Description: A member can only be accessed in the package that defines it, and if it is accessed in another package, the class that implements this method

Members that are decorated with protected (variables or methods) can be called inside a class, other classes under the same package can be called, and subclasses can be called, and other places cannot be called, i.e. in other

Must be a subclass of the class to which the member belongs.

3. Default

No modifier (default), indicating the package access rights (friendly, the Java language is not friendly this modifier, so that the name should be derived from C + +), the same package can be accessed, access rights are package-level access;

4. Private

Working with objects: members

Description: A member can be accessed only in the class in which it is defined

5. Abstract

Working with objects: classes, interfaces, methods

Description: The class includes methods that are not implemented and cannot be instantiated. If it is an abstract method, the method body

is empty, the implementation of the method is defined in the subclass, and the class containing an abstract method must be an abstract class

6. Final

Working with objects: classes, methods, fields, variables

Description: A class that is defined as final does not allow subclasses, cannot be overwritten (not used for dynamic queries), field values

Not allowed to be modified.

7. Static

Working with objects: classes, methods, fields, initialization functions

Description: The inner class known as Static is a top-level class, and it is irrelevant to the members of the containing class. A static method is a class method that is directed to an instance of the owning class rather than the class.

A static field is a class field, and no matter how many instances of the class that the field is in, there is only one instance of the field that is pointed to the owning class instead of the instance of the class. The initialization function is

Executes when the class is loaded, rather than when the instance is created.

9, synchronized

Working with objects: methods

Description: For a static method, the JVM locks the class it is in before execution, and for a non-static class method, locks a particular object instance before execution.

10. Volatile

Working with objects: Fields

Description: Because asynchronous threads can access fields, some optimizations do not necessarily work on fields.

Volatile can sometimes replace synchronized.

11, transient

Working with objects: Fields

Description: The field is not part of the object's persistent state, and the fields and objects should not be strung together.

12, STRICTFP

Working with objects: classes, methods

Description: All methods in the STRICTFP decorated class hide the strictfp modifier, and all floating-point methods executed by the method

Calculation compliance: IEEE 754 standard, all values including intermediate results must be expressed as a float or double type, and cannot be exploited

The additional precision or representation range provided by the local platform floating-point format or hardware.

 

Processes and Threads

  

In the concurrency program, there are two basic execution units: processes and threads.

a Process is an independent execution environment. Processes have a complete, private, basic runtime resource, especially every process has its own memory space.

A process is often seen as a synonym for a program or application. However, the applications that users see may actually be multiple, collaborative processes. To facilitate interprocess communication, the vast majority of operating systems support IPC (Inter process Communication, interprocess communication), such as pipe and socket sockets. IPC can be used not only for communication between processes in a unified system, but also for process communication between different systems.

Most implementations of a Java virtual machine are implemented as a separate process. Additional processes can be created by using the Processbuilder,java application. Multi-process applications are beyond the scope discussed in this section.

Threads sometimes referred to as a lightweight process. Both processes and threads provide a running environment. But creating a new line turndown creating a new process requires fewer resources.

threads exist in the process-at least one thread per process. The resources of the process are shared among multiple threads of the same process, including memory and files. This is done for efficiency reasons, but may lead to potential communication problems.

Multithreading is an important feature of the Java platform. If we are going to do a "system" thread calculation on threads such as memory management and signal processing, then every application has at least one thread,

or multiple threads. But from the programmer's point of view of the application, we always start with a thread that is called the main thread. This thread is able to create other threads, which we'll discuss in the next section .

Thread Object

Each thread is associated with an instance of the class thread. In Java, there are two basic ways to use the thread object, which can be used to create a concurrency program.

When an application needs to initiate an asynchronous task, it simply generates a thread object, which directly controls the creation of the thread and manages it.

Give the application's task to the executor (executor) so that the management of the thread can be removed from the program.

The first way to inherit the thread class is to implement the Runnable interface in the second way

The Main method is also executed by a thread, which is called the main thread; main{m1{};   M2 ();  M3 (); }

Benefits of threading using the Runnable interface 1. Unbind thread from thread functionality 2. Preserving the inheritance characteristics of a class

Public class Threaddemo {public static void main (string[] args) {//the reference to the parent class refers to the object of the subclass Th              Read T=new MyThread ();               Thread t1=new MyThread1 ();             Start thread T.start ();         T1.start (); }}//Inherit the thread class to create threads classes MyThread extends thread{//thread to do content public void run () {for (int i=0;i<100;i ++){  
System.out.println ("Who Are You?") "+i);
}
}
}
class MyThread1 extends thread{
//What the thread is going to do
Public void Run () {
for (int i=0;i<100;i++) {
System.out.println ("Check the water meter?")  "+i);
}
}
}

  

public class ThreadDemo2 {public    static void Main (string[] args) {         Runnable r1=new MyRunnable1 ();          Runnable r2=new MyRunnable2 ();         Thread t1=new thread (r1);          Thread t2=new thread (r2);          T1.start ();          T2.start ();     }} Class MyRunnable1 implements runnable{public    void Run () {for        (int i=0;i<10;i++) {             System.out.println ("Who Are You?");}}}    Class MyRunnable2 implements runnable{public     void Run () {for        (int i=0;i<10;i++) {               System.out.println ("Open check meter?");}}                             

 

public class ThreadDemo3 {public static void main (string[] args) {  Executorservice es=executors.newfixedthreadp    Ool (3);  Runnable r1=new Runnable () {public   void run () {   System.out.println ("hello!");   }  };  Runnable r2=new Runnable () {public   void run () {   System.out.println ("helloworld!");   }     };  Runnable r3=new Runnable () {public void run () {  
System.out.println ("hellokitty!"); } }; Es.submit (R1);      Es.submit (R2);   Es.submit (R3); }}

The frequent opening of new threads from the system consumes system resources and affects the performance of the program, and we can design a thread pool that, after the threads run, will return to the thread pools.

Create a thread pool object Executorservice es=executors.newfixedthreadpool (number) using the class provided by JDK5;

Java Threads and Java modifiers

Related Article

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.