In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Java multithreading application scenario and application purpose example analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
A popular explanation of multithreading first:
Multithreading is used for stacking processing, just like a large mound, and a bulldozer is very slow, then 10 bulldozers will deal with it together, of course, the speed will be faster, but due to location limitations, if 20 bulldozers, then bulldozers will have mutual avoidance, friction and crowding with each other, but not as good as 10 processing, so multithreading, the number of threads to open properly, can improve efficiency.
The purpose of multithreading:
1. Throughput: when you do WEB, the container helps you do multithreading, but it can only help you do the request level. To put it simply, it is a request for one thread (such as struts2, which is multithreaded, and each client request creates an instance to ensure thread safety), or multiple requests for one thread. If it is single-threaded, it can only process a user's request.
2. Scalability: improve performance by increasing the number of CPU cores.
Usage scenarios of multithreading:
1. Common browsers, Web services (web is now written by middleware to help you control threads), web handles requests, various dedicated servers (such as game servers)
2. Servlet multithreading
3. Download FTP and operate files with multiple threads.
4. Multithreading used in database
5. Distributed computing
6. Tomcat,tomcat is multithreaded, and hundreds of clients access the same WEB application. After tomcat is connected, the subsequent processing is thrown to a new thread, which finally calls our servlet program, such as doGet or dpPost method.
7. Background tasks: such as regularly sending emails to a large number of users (more than 100W); regularly updating configuration files and task scheduling (such as quartz), and some monitoring for regular information collection
8. Automatic job processing, such as regular backup of logs and databases
9. Asynchronous processing: such as sending Weibo and keeping a log
10. Page asynchronous processing: such as checking large quantities of data (there are 100000 mobile phone numbers, check which are existing users)
11. Data analysis of the database (too much data to be analyzed), data migration
12. for multi-step task processing, threads with different numbers and characteristics can be selected according to step characteristics, and multi-task can be divided by one main thread to multiple threads.
13. Desktop application development, a time-consuming calculation opens a thread, and a progress bar is added to the foreground to display
14. Swing programming
Take a little chestnut:
A text file has 100m, all strings. I want to split the string, cut the abdomen every time the length of N is reached, and finally find the collection of the completed string.
Single threading:
Read the text file data, scan all the data, split one by one, the final consumption time = file transfer time (text data loaded into memory) + segmentation process consumption
Multithreading:
A thread is specially set to perform the operation of loading data. At this time, if the loaded data reaches a set value, a thread cutting process is started, and so on, multiple threads that split strings can execute concurrently, and the utilization of CPU is improved (the processor is not occupied in the process of file transfer, but part of the loaded data can be allocated to the split thread to occupy the processor to perform the task)
Single-threaded processing, the file loading process, the processor has been idle, but also added to the total execution time, serial execution split total time, equal to each split one time * the number of strings after syncopation, execute the program, it is estimated that it will be good to wait a few minutes to finish processing.
Multi-thread processing, file loading process and split process, split process and split process, all exist concurrency-split task is executed in the process of file loading, and multi-thread parallel processing is performed in the process of split task execution. the total time consumption can be much higher than that of a single thread, or even several orders of magnitude.
After reading the above, have you mastered the application scenario of Java multithreading and the method of application example analysis? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.