1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is the difference between wait() and sleep()?
wait() releases the lock and needs notify() to wake up. sleep() keeps its locks and wakes up on its own.
What's the difference between deadlock prevention and deadlock avoidance?
Prevention removes a condition outright, like a fixed lock order. Avoidance checks at runtime if granting a resource could cause deadlock.
What is the semantics of a counting semaphore?
acquire() decrements the permit count, or blocks if it's zero. release() increments it and wakes a waiting thread.
What is object serialization, and how do you implement it?
Serialization turns an object's state into bytes. Implement it via Serializable, or Externalizable, which needs writeExternal() and readExternal().
What is resource ordering, and why does it prevent deadlock?
Every thread acquires locks in the same fixed order, which stops a circular wait from forming.
Why is overuse of threads bad?
Too many threads waste more context-switching than working and too many threads can exhaust memory for stacks. Use a bounded pool instead.
What is a monitor?
A monitor gives one thread exclusive access to an object’s data by tying a lock to the object. entering a synchronised method acquires it and other threads block and queue until it’s released.
Can a constructor be synchronized? Why or why not?
No, the object isn't visible to other threads until construction finishes, so there's nothing to lock yet.
How can a reentrantlock be fair?
new ReentrantLock(true) gives the lock to the longest-waiting thread first, at the cost of some throughput.
Name three ways processes on the same processor can communicate. If any require hardware support,
Shared memory: processes share the same physical memory via the MMU, but still needs a semaphore for coordination.
Message passing: the OS copies messages between processes, no hardware needed.
Semaphore: OS provided coordination, built on hardware atomic instruction like compare and swap
Explain what is meant by encapsulated classes.
Encapsulation bundles a class’s data with the methods that operate on it, while hiding the internal state from the outside