In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to deeply analyze the Java programming language from three aspects, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Java programming language requires us to learn relevant knowledge, and many people will say that we should pay attention to the introduction of related issues. Let's take a look at how to understand and learn the Java programming language from three aspects. I hope you all get something.
My understanding of processes and threads is mainly a book I read when I was a student, probably called "C++ face object multithreaded programming", which was written by Americans. Later, to learn the Java programming language, has been just so-so, to complete the task as the goal, not like learning C++ as a solid foundation (the foundation of C++ almost forgotten, Khan). This is not to do things and encounter trouble, after investigation and solution, there are a few simple knowledge points to take notes.
The first is run () and start (). Flipping through the code I wrote before, I started the thread with start (), but this time I was confused and ran with run (). No wonder I didn't make a mistake. I believe there are many Java programming language programmers like me who click on a point to view the list of methods and take it for granted according to the name of the method. This method can quickly start to do things, but things like multithreading still need to lay a solid foundation, otherwise it will be a lot of trouble.
Run () is just a normal method, a method defined by the Runnable interface to perform what the thread will eventually do, and there is nothing special about it, just like the main method, when a thread is started, the run () method is called. So, the run () method does not create multithreading, and what is in the run () method is still running in the caller thread.
The start () method is defined by the Thread class, and it is really responsible for starting a thread. After calling this method, a new thread is created from the thread (emphasizing that the new thread is created from the current thread because some properties such as daemon will be inherited), and then the run () method is executed on the new thread.
The second one is InterruptedException. Typically, we often use while loops in the run () method, and each loop is usually called by Thread.sleep (long), which sleep (long) method throws an InterruptedException. The previous understanding of this exception was wrong, thinking that it was a "mistake", but in fact it just indicated a state. It's a bit of a mouthful to read the official documentation. Simply put, this exception is thrown to indicate that the thread has received an interrupt request (you can also understand that the thread is being terminated, usually, but not absolutely. For thread safety and data consistency, the Java programming language advocates a mild manual abort, which means that the code in the run () method has a chance to decide when to exit, such as an external call to interrupt () to interrupt the thread. The interrupt exception received by sleep () means that an interrupt request signal is sent from the outside of the sleep, and if there is no need to clean up the operation, you can exit the while loop and end the thread. My previous code is catch to hit a log, although it works properly, but it is wrong. Sweat again!
The third is the difference between Thread.interrupted () and thread.isInterrupted () (the latter thread represents an instance of Thread). Both return to the current state of the thread, the difference being that the former returns to the current state and then resumes that state. For example, Thread.interrupted () gets true, but the thread state is immediately set to false. If you don't want to change this state, you can use isInterrupted (), such as Thread.currentThread.isInterrupted (). In addition, the interrupt state can be changed by some operations, so you can't just use this state to determine whether the segment thread is about to exit. The thread should set another exit flag (if you need to control whether the thread is running or not).
This is the answer to the question on how to deeply analyze the Java programming language from three aspects. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.