Milleniumlegend
IS-IT--Management
- Dec 16, 2003
- 135
I am gettig the following error.
C:\programs\java\queue>java TestBlockingQueue
Exception in thread "Thread-1" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Exception in thread "Thread-3" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Exception in thread "Thread-4" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Exception in thread "Thread-2" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
C:\programs\java\queue>java TestBlockingQueue
Exception in thread "Thread-1" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Exception in thread "Thread-3" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Exception in thread "Thread-4" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Exception in thread "Thread-2" java.lang.NullPointerException
at Consumer.run(Consumer.java:21)
Code:
import java.util.concurrent.BlockingQueue;
import java.io.PrintStream;
import java.util.Date;
public class Consumer extends Thread
{
private BlockingQueue blockingQueue;
private String consumerName;
private PrintStream printStream;
public Consumer(String consumerName, BlockingQueue blockingQueue, PrintStream printStream)
{
consumerName = this.consumerName;
blockingQueue = this.blockingQueue;
printStream = this.printStream;
}
public void run()
{
while (true)
{
try
{
printStream.println(this.consumerName + blockingQueue.take());
String time = String.format("%tc",new Date());
printStream.println("Getting item on BlockingQueue at time: " + time);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
}
}