multithreading - What happens to the opened resources in Thread.yield , sleep and wait methods in java -
i asked in interview, multi-threading
happen opened resources in multi-threading if call thread.yield() or sleep(100000) or wait() methods after opening resource. closed or in open ? please me in understand multi-threading.
sleep(100000)
causes thread stop executing given amount of time. open resources remain open until then.
yield()
method pauses executing thread temporarily giving chance remaining waiting threads of same priority execute. if there no waiting thread or waiting threads have lower priority same thread continue execution. assuming thread gets priority, open resources closed. otherwise, can remain in open state.
wait()
says “i’m done cpu timeslice. don’t give me timeslice until calls notify().” sleep(), os won’t try schedule task unless calls notify() or 1 of few other wakeup scenarios occurs. , open resources remain open unless notify gets called , open resources closed.
Comments
Post a Comment