- Methods in object class
· wait → throws interruptedException
· notify
· notifyAll
Remember → they are final and must be called from within a synchronized context, otherwise illegalmonitorstate exception is thrown at runtime.
- yield , sleep are static members of Thread class.
- stop , resume , suspend are deprecated members of Thread class.
- InterruptedException is checked exception.
- Given
synchronized (expression){…..}
· expression may evaluate to reference to object.
· expression cannot evaluate to primitive type or null.
· If execution block completes ( abruptly or normally )the lock is released.
· synchronized statements can be nested.
· synchronized statements with identical expression can be nested.
- Thread.yeild method
· may cause the current thread to move from runnable to ready state .
· It isn’t guaranteed i.e. same thread may start executing again.
- Thread.sleep method
· makes thread to move from running to not – runnable state
· thread takes lock with it if it has got one.
- Thread class inherits Runnable interface.
- A dead thread can never be restarted.
- When overriding the ‘run’ method of the Thread class remember the following points
· the prototype must be public void run(){}
· Access modifier must be public.
· ReturnType must be void.
· No arguments must be specified and if done it doesn’t cause error but it can’t be used to start a new thread.
→ if the class implements Runnable interface then it has to possess run method with no arguments specified otherwise compiler error is caused.
· it must not declare any new checked exception in its throws clause.
· it must not be declared static
· It can declare unchecked exception in its throws clause.
· If start method is called twice then illegalThreadStateException is thrown.
- the run method in Thread class is empty method which does nothing.
- join,sleep,wait methods declare InterruptedException in their throws clause.
- If we extend thread class or implement runnable interface then the present run() method must not be marked static ,if it is marked it causes compiler error.
- The priority of a thread can be altered after the thread has been started using setPriority method .The code compiles fine.