Multi Threading


  1. What is Thread Group ?
    Based on functionality we can group thread into a single unit ,which is nothing but Thread Group i.e. Thread Group contains group of thread. In addition to Thread ,Thread Group can also contain sub-thread group.
    The main advantage of maintaining thread in the form thread group is ,we can perform common operation very easily.

    Code:
  2. What is yield() method ?
    Theoretically, to ‘yield’ means to let go, to give up, to surrender. 
    The yield() method of thread class causes the currently executing thread object to temporarily pause and allow other threads to execute. Note that it’s only a hint, though, and not guaranteed to have any effect at all. This method is persent in java.lang.Thread class in java. Syntax  :- public static native void yield() 
    Some platform wouldn't support for yield() method. The purpose of yield() method causes to pass current executing thread to give the chance for the remaining waiting thread of same priority.
  3. What is join() method ?
    If a thread wants to wait until completion of some other thread then we go for join() method.
    Syntax:
    public final void join() throws InterruptedException
    public final void join(longmiliseconds) throws InterruptedException
    public final void join(longmiliseconds,int nanoseconds) throws InterruptedException
    Every join method thrwos interrupetd exception which s checked Exception, hence compulsory we hould handle this exception either by using try-catch or by throws keyword, otherwise we will get compile time error.
























Comments

Popular posts from this blog

Sealed Classes and Interfaces in Java

Introduction of RabbitMQ

RabbitMQ Installation on Windows