SCJP Study Notes


Threads

  • A Java program runs until the only threads left running are daemon threads.
  • wait(),notify() and notifyAll() are the methods of Object class and wait() throws InterruptedException. They can be called only from synchronized code.
  • A Thread can be set as a user or daemon thread when it is created.
  • Calling the start() method does not immediately cause the thread to run, it just makes the thread eligible to run.
  • You can explicitly set the priority of a thread using setPriority(), and you can get the priority of a thread using getPriority().
  • You can not restart a dead thread by calling its start() or run() methods.
  • The specifics of how thread priorities affect scheduling are platform dependent.
  • Thread scheduling algorithms are platform dependent
  • You can obtain a mutually exclusive lock on any object.
  • Synchronized keyword ensures only one thread at a time may access a method or object.
  • A thread can obtain a mutually exclusive lock on an object by calling a synchronized method on that object.
  • The join, sleep and wait methods name the InterruptedException in its throws clause.
  • A timeout argument can be passed to join, sleep and wait methods.
  • wait, notify and notifyAll methods should only be called by a thread that holds the lock of the instance on which the method is invoked.
  • sleep and yield methods are static members of Thread class.
  • InterruptedException is a checked Exception.
  • Any overriding method of a synchronized method is NOT implicitly synchronized.
  • The behavior of Thread.yield is platform specific.
  • The Runnable.run method does not have a throws clause; so any implementation of run can not throw a checked exception.
  • Invoking the start method on a thread that has already been started will generate an IllegalThreadStateException.

contents | previous | next