Priority and Daemon threads in Java.

Posted by admin On January - 19 - 2010

Every thread in Java has a priority . By default , the priority is NORM_PRIORITY or 5. There are three such type of Priorities.

NORM_PRIORITY:

MAX_PRIORITY:

MIN_PRIORITY:

Priority in java are just a normal things like we want to set some threads property high and some’s priority very low. it is commom phnomena. you can understand it with the given below code

class Priorty extends Thread
{
 int num;
 public Priorty(int num)
 {
 this.num = num;
 }
 public void run()
 {
 for (int count = 0; count <= num; count++)
 {
 System.out.println("Count = " + count);
 }
 System.out.print(Thread.currentThread().getName());
 System.out.println("Its priority was " + Thread.currentThread().getPriority());
 Thread.currentThread().setPriority(MAX_PRIORITY);
 System.out.println("Its Priority now is " + Thread.currentThread().getPriority());
 }
 public static void main (String args[])
 {
 for (int ctr = 0; ctr < 2; ctr++)
 {
 Priorty Objprior = new Priorty(5);
 Objprior.start();
 Objprior.setName("Thread" + (ctr+1));
 }
 }
}

The result will be like this.

run:
Count = 0
Count = 1
Count = 2
Count = 3
Count = 4
Count = 5
Thread1Its priority was 5
Its Priority now is 10
Count = 0
Count = 1
Count = 2
Count = 3
Count = 4
Count = 5
Thread2Its priority was 5
Its Priority now is 10
BUILD SUCCESSFUL (total time: 3 seconds)

DAEMON THREADS:

Before starting a engine we need to do some task like open the door, check the fuel and some thing like this. so daemon thread is a service provider which is used to start other tasks. like Garbage collction.

Gabage collection is a daemon thread.  Daemon threads are basically is a thread. it is just like a normal thread. but if you want to find the daemon thread you have to fint it via  getDaemon . Daemon is the service provider.

public class TestDaemon implements Runnable
{
Thread Objth1,Objth2;
public TestDaemon()
{
 Objth1 = new Thread (this);
 Objth1.start();
 Objth2 = new Thread(this);
 Objth2.setDaemon(true);
}
public void run()
{
 System.out.println(Thread.activeCount());
 System.out.println(Objth1.isDaemon());
 System.out.println(Objth2.isDaemon());
}
public static void main (String args[])
{
 new TestDaemon();
}
}

The Output will be like this.

run:
2
false
true
BUILD SUCCESSFUL (total time: 1 second)
VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Share with others:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Twitter
  • Twitthis
  • Yahoo! Bookmarks
  • Yahoo! Buzz

One Response to “Priority and Daemon threads in Java.”

  1. kennytren says:

    Hollywood Love Rugs specializes in selling elegant, exotic and unusual rugs to the Hollywood Entertainment community, including motion picture, television and legitimate theater productions. They have mastered the art of locating hard to find area rugs for the home and office. The co-owner of Hollywood Love Rugs, Frank Conn, has been selling in Hollywood high-end area rugs and home rugs for over thirty years to entertainment trade and numerous celebrities. They have also been supplying high quality are rugs to television series, trade shows, motion pictures and movies. Art directors in Hollywood love Hollywood Love Rugs because of the exclusive collection the company brings, personal service and custom orders.

    Hollywood Love Rugs comes with a unique Hollywood experience that no other area rugs company in the industry has. This unique experience makes them unique. The demands of the Hollywood industry are high; unless a company offers its best quality and service, it cannot survive. One can see their area rugs in movies such as Kevin Costner’s Dancing with Wolves, Michael Mann’s movie Heat, Cher’s Malibu home, MTV awards, Men in Black II, just to name a few.

    Frank Conn is dedicated to bringing the customer best quality area rugs at the most competitive prices. Their product range covers elegant, unique and unusual area home rugs, pillows in a large range of materials, including fur, faux fur, cowhide and sheepskin, as well as shag rugs, flokati rugs and decorative pillows. They also handle custom orders effectively with great creativity. Interior designers, decorators, art directors of television, movie and trade shows will find Hollywood Love Rugs a great asset. Their current operation is now planning to have 35,000 products indexed in their website and third-party shopping portals. Hollywood Love Rugs comes as a major competitor to every area rug retailer online.

    Hollywoodloverugs.com is a state of the art online store from which area rug lovers who are keen in purchasing exotic high end area rugs at the most affordable pricing can conveniently order from the comfort of their homes. They can also make use of the services of Hollywood Love Rugs to source rare collection of home rugs and interior decor items. Their ability to find exotic rugs within short notice is just unbeatable. This contributes to their soaring popularity in the Hollywood trade. Their online store offers a safe shopping environment for the purchase of your home rug. While having a large collection of exotic and elegant area rugs and home decor items, Hollywood Love Rugs still maintains a boutique personality dedicated to satisfying individual customer’s needs.

    http://www.hollywoodloverugs.com

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)

Leave a Reply

Help Pakistan's Flood Victims
Ad-Space Available
Our Sponsor

About Me

I will tell you Later

Twitter

    Photos

    Kis galiKabristanDSC09340DSC09302