laitimes

To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?

<h1 class="pgc-h-arrow-right" data-track="1" > scenario</h1>

Students who have the desire to explore should be like me, when looking at the JDK source code, followed by the final, there will be a native method, similar to the following method

See this native, indicating that it has been dug to the core, to this step, or it is not clear how to get the default time zone of the system, then what to do, JDK code can only follow here.

Switch to OpenJDK, source code download method: gitee.com/mirrors/ope...

<h1 class="pgc-h-arrow-right" data-track="6" > what is native</h1>

Native is a computer function, and a Native Method is an interface for Java to call non-Java code. Method implementations are implemented in non-Java languages, such as C or C++.

<h1 class="pgc-h-arrow-right" data-track="8" > what to think of the native source code</h1>

Take **private static native String getSystemTimeZoneID(String javaHome)** as an example

As shown in the figure, find the GetSystemTimeZoneID method under the TimeZone .c

To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?
To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?

Important: Call mapping functions related to different platforms

When you go to look for findJavaTZ_md method, you find that there are two directories in solaris and windows.

To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?

Looked up the differences between the two directories:

The simple understanding is:

Under the window system, use the JDK code compiled under the windows directory

Under the platform of the unix system, the JDK code compiled in the solaris directory is used

<h1 class="pgc-h-arrow-right" data-track="21" > understand findJavaTZ_md method execution under different systems</h1>

<h1 class="pgc-h-arrow-right" data-track="22" > Windows system</h1>

The comment is clearly written to get the current time zone in the "Time Zones" registry

How to set the time zone:

To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?

At that time, where the selection value on the zone was taken, as stated above, was taken in the registry

Open registry: Regedit--&gt;

<h1 class="pgc-h-arrow-right" data-track="30" >unix system platform</h1>

The comments on the findJavaTz_md() method are clearly written: map the platform time zone ID to the Java time zone ID

steps:

1. Use &lt; Java home&gt;/lib/tzmappings. If the "TZ" variable is not found, proceed to step 2

2、 tz = getPlatformTimeZoneID(); Perform a Linux-specific mapping that returns a time zone ID if found, or null otherwise

【Linux】Centos7 modifies the system time zone timezone way:

To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?

Modify the time zone

To explore the jd.D.'s core underlying source code, it is necessary to grasp the native usage scenario What is the native source code How to see it findJavaTZ_md?

3. Compare the files in the /etc/localtime and "/usr/share/zoneinfo directory, if they are consistent, they will return the time zone ID, and if not, go to step 4

4. Return to GMT

Read on