12-03-2011, 03:26 PM
multi threading.ppt (Size: 120.5 KB / Downloads: 56)
Mutli Threading in Java
• Java provides native support for multithreading.
• This support is centered on the java.lang.Thread class, the java.lang.Runnable interface methods
• public void start()
Starts the thread in a separate path of execution, then invokes the run() method on this Thread object.
• public void run()
If this Thread object was instantiated using a separate Runnable target, the run() method is invoked on that Runnable object.
• public final void setName(String name)
Changes the name of the Thread object. There is also a getName() method for retrieving the name.
• public final void setPriority(int priority)
Sets the priority of this Thread object. The possible values are between 1 and 10.
• public final void setDaemon(boolean on)
A parameter of true denotes this Thread as a daemon thread.
• public void interrupt()
Interrupts this thread, causing it to continue execution if it was blocked for any reason.
• public final boolean isAlive()
Returns true if the thread is alive, which is any time after the thread has been started but before it runs to completion.
• public static void yield()
Causes the currently running thread to yield to any other threads of the same priority that are waiting to be scheduled
• public static void sleep(long millisec)
Causes the currently running thread to block for at least the specified number of milliseconds
• public static Thread currentThread()
Returns a reference to the currently running thread, which is the thread that invokes this method.