Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement JAVA Class loading and Multithreading

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "JAVA class loading and how to achieve multithreading", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "JAVA class loading and multithreading how to implement" it!

The first order I thought of was "static first from parent to child", but the constant of the Sting type of the final keyword was declared at the end

Correct output result: C

To get rid of final is to go from father to son, static first.

Output result:

Then everyone began to discuss the reason, my guess is that only the memory address (wrong X) is called.

And then it started again.

The String type becomes the Integer,String reference data type and Integer is the wrapper class

Running result:

When the type is changed, it is executed from parent to child, and static methods can be called directly through the class name.

Reason: use final and static to modify a field field at the same time, and the field is of basic type or String type. Calling this field class will not initialize it.

The constant exists in the constant pool, and there is essentially no class that references the constant, so it will not be initialized.

# Segmentation Line #

How many states does a thread have? Http://mp.weixin.qq.com/s?__biz=Mzg2ODA3NjA1MA==&mid=2247483821&idx=1&sn=c4490e0f2a78d98dbcc98aaa089fb5f6&chksm=ceb09ed0f9c717c6274f909383b6ce3623d6ad3f731a822c83d9fc5dd59aafae6edd601fc05d#rd

CountDownLatch: the thread wakes up after performing a series of operations. Down is quite--

Demo:

CyclicBarrier: loop to a certain point before it is blocked is equivalent to + +

Demo:

Semaphore: control of concurrent threads

Demo

How many ways can you create a thread?

1: inherit the Thread class and implement the Runable interface

2: implement the Callable interface, which is obtained from the thread pool

How to create a thread pool? Three species

Which one do you actually use? According to Alibaba's development manual, the requirements for concurrent processing

[mandatory] Thread resources must be provided through the thread pool, and it is not allowed to explicitly create threads in the application.

Created by new ThreadPoolExecutor ().

At this point, I believe you have a deeper understanding of "JAVA class loading and how to implement multithreading". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report