Analysis of Java multithreaded callback method instance
The so-called callback is that the client program C calls a method a in the service program s, and then s calls a method B in C at some time. For C, this B is called the callback method.
Let's take a practical example to understand:
This example sets up a questioner and a respondent. When the respondent needs to answer a very profound question of the questioner, it takes a lot of time to find it, and the questioner starts to do other things,
After the respondent finds the answer, tell the questioner the answer.
I Class of questioner
When it comes to thinking for a long time, sleep and inherit thread
2、 Class of questioner
Operation results:
It can be seen that the questioner must first explain how the respondent answers the question,
Then the questioner does his own thing, and the respondent begins to think about the answer.
The specific expression of the contact information explained here is to instantiate the callback interface and implement the answer method in the questioner's class.
Most of the content has been reflected in the code, so I won't repeat it here.
summary
The above is all about the analysis of Java multithreaded callback method examples in this paper. I hope it will be helpful to you. Interested friends can continue to refer to this site: Java multithreaded programming examples, talking about the advantages and code examples of Java multithreading, Java using future to obtain multithreaded running results in time, and other relevant contents of this site. If you have any questions, you can leave a message at any time, and the editor will reply to you in time. Thank you for your support!