This is one question, asked to me a interview, on which I have no idea what he is asking.
If you can help on the same:
sleep, wait, notify, yield
- which one is a callback?
None of the methods you list are callbacks. The entire Thread
class contains only one user-overridable method, and that is run
, which may be considered a callback method for that class because it is called by Thread
's internals. However, a best practice is not to extend Thread
at all. Supply your own Runnable
implementation, which has its callback run
method.
None of those look like traditional callbacks. A callback function/method is something you register to be called once an operation is complete (possibly asynchronously if the task is scheduled in another thread).
Sleep, wait and yield essentially block execution until their conditions are met. Notify wakes threads blocked by wait.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With