This is the simplest and most basic infinite loop.
While (1) While (true) (;;)......
However, in programming, some dead loops that are not so basic are often used,
Here are some of the endless loops I encountered in programming.
The method is not remembered, just a rough description.
1 (recursive endless loop)
2 (AOP endless loop)
This is a variant of recursive endless loops.
All spring learners know that AOP is designed for cross-section programming,
I remember reading a blog online saying that Implementing AOP in spring not only uses dynamic proxy of JDK but also cglib. Both interfaces and object classes can be dynamically represented.
I have never been familiar with dynamic proxies. If you are bored one day, try to understand:
Cglib (code generation Library)
70238002
I have read several articles on the Internet and tried to write a JDBC transaction annotation transaction.
This figure does not know whether it can be explained. It means that when using cglib for dynamic proxy, be sure not to call the tostring method of the proxy object. Otherwise, an indirect recursive endless loop occurs.
3 (an endless loop of File status updates, which is a bit extreme and may not be met)
This is a series of business logic.
When I was in my sophomore year, I used Android. I used androidstudio to have a game Lenovo smart traffic. I needed three people to use android to take an app. At that time, I was thinking about a problem. When three people make an app, they must make an app under a LAN, so I can't make a software so that three people can operate on a project at the same time.
The idea is as follows:
The background runs a thread to traverse all the files in a specified project. If the file content of a file has recently changed. Send the file to your friends. A friend writes the changed file content to the file ,. Of course, the read and write content is also completed by the background thread.
Later, this thing was indeed made, but there was a coding problem and I didn't care about it anymore.
At the same time, there are two questions about the endless loop.
(1) an endless loop is required in the Child thread. This endless loop is used to traverse the file and view the file change status. Of course, this is a normal endless loop, which is what we need. It is nothing more than a loss of software performance.
Later, I found a file listener class on the Internet.
Watchservice watcher = filesystems. getdefault (). newwatchservice ();
This class uses the observer mode. No longer need to use an endless loop, which undoubtedly improves the performance of the software.
(2) Another endless loop occurs during file read/write.
When the file changes, the client sends the file to a friend because each client has the same function.
This is the problem. When file a changes, it is sent to file B. After file B updates the file locally, the local file changes again, B will send the same file as a to. Changing the File status leads to an endless loop.
Let's talk about some endless loops in programming (recursive endless loops, AOP endless loops, and business endless loops)