Wednesday, June 14, 2006

Daemon Thread

Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system.

"setDaemon" method is used to create a daemon thread.

Thursday, June 01, 2006

Runnable Interface

class MyRunnable implements Runnable
{
public void run()
{
System.out.println("Inside run()");
}
}


Next, create an instance of the class and construct a thread, passing the instance of the class as an argument to the constructor:

MyRunnable mc = new MyRunnable();
Thread t = new Thread(mc);


To start the thread, use the start() method as shown here:
t.start();

Wednesday, May 24, 2006

Basics of Thread

1). Threads operate on their on own copies of instance variables.
2). In synchronized methods wait() causes the thread to give up the monitor.
3). If the reference to the thread is set to null, thread doesn't stops executing.
4). In synchronized methods yield() and sleep() doesn't causes the thread to give up the monitor.

Monday, May 22, 2006

Thread eligible to run

When a new Thread class is instantiated and its start method is called, system resources required for the thread are allocated. The thread is made eligible to run and must content with other threads for the CPU. When the scheduler decides to move it to the running state the run method is then executed.

Priority from Parent Thread to Child Thread

The default priority when a Thread is created is 5. When a Thread is created from within a Thread, the priority will be passed on from parent to child.

Thread.yield()

The yield method provides a hint to the JVM that if there are other runnable threads, the scheduler should run one instead of the current thread. The JVM may interpret this hint in any way it likes - that is how the yield is handled is dependent on the JVM implementation for the operating system.