• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread help

 
Hung Chan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile my source code, I got the following compile error. I don't know what wrong in my code.

C:\src>javac OrderManager.java
OrderManager.java:7: <identifier> expected
orderProcessingThread.start();
^
1 error

C:\src>


It seems the compiler expect some parameters I have to pass into start() method. I check my run() method. It looks ok! Can someone give me some help! Thanks!

public class OrderManager {

private PriorityQueue mOrders = new PriorityQueue();
private OrderProcessing orderProcessing = new OrderProcessing(mOrders);
private Thread orderProcessingThread = new Thread(orderProcessing);

orderProcessingThread.start();

public void addOrder(Order order) {
mOrders.add(order);
}
:::
::
}


import java.util.Iterator;

public class OrderProcessing implements Runnable {

PriorityQueue pq;

public OrderProcessing(PriorityQueue pq) {
this.pq = pq;
}

public void dispatch(PriorityQueue queue) {

Object item;

while ((item = queue.highest()) == null) {
try {
wait();
}
catch (InterruptedException err) {
System.out.println(err);
}
}

queue.getQueue().remove(item);
Iterator it = queue.getProcessors().iterator();
while (it.hasNext()) {
((OrderProcessor)it.next()).process(item);
}
}

public void run() {

while (true) {
try {
Thread.sleep(100);
dispatch(pq);
}
catch (InterruptedException err) {
System.out.println(err);
}
}
}
}

[ June 06, 2004: Message edited by: Hung Chan ]

[ June 06, 2004: Message edited by: Hung Chan ]
[ June 06, 2004: Message edited by: Hung Chan ]
 
Vali GB
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

the call to



must be inside a already running thread like the Main method

good luck!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!