midturm Flashcards
How many thread objects execute at once per CPU
At any moment, at most one thread object is executing per CPU
what are the behaviours of thread
Thread: defines actual behaviour
What is the thread state lifecycle
- new
- ready
- running
- waiting
- sleeping
- blocked
- dead
what are the behaviours of interface
Interface: defines desired behaviour
How can you put a thread on hold
- yield ()
- sleep ()
- join ()
- wait ()
- suspend ()
Thread.yield()
Static method
Causes the thread executing the method to allow another thread of the same priority to run
Should be used for non-timesliced systems
When does a thread die?
Threads die when run() method returns
how to check if the thread is still viable
isAlive()
what arguments does join() take?
Join ([timeout])
join()
Join method causes current thread to wait until the thread of the threadObject on which the join method is called terminates (threadObject.join();)
Join lets another thread finish or gives it a limited amount of time to finish
Thread.sleep()
Static method
Causes thread to pause for a fixed period of time
what arguments does thread.sleep() take?
Thread.sleep (long milis, [int nanos])
thread.interrupt()
allows another object to interrupt the sleep period
What exceptions does thread.interrupt() throw?
interruptedException – if another thread has interrupted the current thread
IllegalArgumentException – millis is negative or value of nanos is not in the range 0-999999
Blocked
All java I/O methods step out of the running state while paused for response, said to be blocked
ThreadGroup
Can be dealt with as a unit
Hierarchical relationships – parent/child
Method calls sent to a parent group also sent to all its children
Construct your threads with the ThreadGroupName in the constructor
What does the RMI client do?
Obtains a remote reference to one or more remote objects
Invokes methods on those objects
Synchronization problems
Arises when multiple threads access shared data (producer/consumer problem)
Producer fills the buffer/Consumer empties the buffer
RMI interface support layers:
client/server
Stub/skeleton layer
remote reference layer
transport layer
Object monitor lock
Every object has a flag associated with it – called monitor lock
Used with the synchronized key word
All methods accessing shared data should synchronize on the same lock object
Stub/skeleton layer
responsible for managing the remote object interface between the client and server
How many synchronized methods can be active on an object at once?
Only 1 synchronized method may be active on an object at once
All other threads trying to acquire the monitor lock will block
what does RMI involve
RMI involve client and server sides
Remote reference layer
responsible for managing the “liveliness” of the remote objects. Manages the communication between the client/server and virtual machines