Java multi-threaded interviews: sleep, wait, notification, exit - which one is a callback?

This is one question, they asked me an interview in 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?

+4
source share
3 answers

None of the methods you listed are callbacks. The entire Thread class contains only one user redefinition method, and this is run , which can be considered a callback method for this class, because it is called by Thread internally. However, the best practice is not to expand the Thread at all. Deliver your own Runnable implementation, which has its own run callback method.

+5
source

A callback is a method that is created to be called at a specific time / event from another location.

sleep() , wait() and yield() are called by the thread to perform the action. notify() can be interpreted as one, and as such is a more correct answer if it is correct, although not one of them is.

+2
source

None of them look like traditional callbacks. The callback function / method is what you register for the call after the operation completes (possibly asynchronously if the task is scheduled in another thread).

Sleep, waiting, and exiting essentially block execution until their conditions are met. Notify blocked threads blocked by pending.

+2
source

Source: https://habr.com/ru/post/1500719/