Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top