When you use a callback in Java (you can't do that right?), does it block execution until everything is finished? Am I using the wrong terminology. I am familiar on the purpose of a Callback as it relates to Inverion Of Control, Interface, etc., just not the sequence of events.

有帮助吗?

解决方案

Converting to an answer from a comment:

All method calls are synchronous, in that they return a result to the caller. However, a callback implies potential asynchronous behavior wherein you define a method to execute when some action is complete. For that matter, the state of the application may determine whether the call is synchronous (i.e. caching of resources). In order to know whether the underlying action is synchronous or asynchronous you need to read the documentation for whatever library you are using. In summary: read the docs

其他提示

A callback is just a piece of code to execute. It can be invoked synchronously or asynchronously.

Yes.

That's not to say that invoking the callback won't start a new thread internally to do something asynchronously, but the callback method itself is synchronous.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top