public class CubbyHole
{
private int contents;
private boolean available = false;
public synchronized int get()
{
while (available == false)
{
try
{
wait ( );
}
catch (InterruptedException e)
{
}
}
available = false;
notifyAll ( );
return contents;
}
public synchronized void put(int value)
{
while (available == true)
{
try
{
wait ( );
}
catch (InterruptedException e)
{
}
}
contents = value;
available = true;
notifyAll ( );
}
}
public class Producer extends Thread {
private CubbyHole cubbyhole;
private int number;
public Producer(CubbyHole c, int number) {
cubbyhole = c;
this.number = number;
}
public void run() {
for (int i = 0; i < 10; i++) {
cubbyhole.put(i);
System.out.println(“Producer #” + this.number
+ “ put: “ + i);
try {
sleep((int)(Math.random() * 100));
} catch (InterruptedException e) {
}
}
}
}
Home      |      About Us      |     Portfolio      |      Services      |      Courses      |     Career      |      Cost      |      Contact Us
Services
  SEO   
  Link Building
  Data Entry
  Web Design and development
  Web Application development
 

Graphic and multimedia

  E-Commerce Solutions
  Software development
  Web Marketing & Promoting
  Internet Marketing
  IT Outsourcing
  Multimedia/CD Presentation
  Synopsis Ideas
  Project Ideas
  Placement Papers
  Live Project Training
  Programming & Projects
  Faq
  Training @balujalabs
 
 
Method
 

Program To Demonstrate Thread Operator

 

 

 

 

 

 

 

 

 

                                                                                                                                          

1

Following Example Shows How To Start Stop, Suspend, and Resume Threads. It uses the Runnable interface. Threads Like this are useful for Things like Controlling Animation Sequences Or Repeatedly Playing Audio Sample .This Example Uses a Thread that Countess that and prints a String every second. The thread starts when the applet is initialized. It continues to run until the user leaves the page, if the user returns to the page (and all is well) the thread continues from where it left off. This allows applets to retain their states while the user is away.

2

Program To Demonstrate The Use Of Multithreading

3 Program To Demonstrate Thread Operator
4 Program To Demonstrate Priority Thread
5

Program To Demonstrate Multithreading