2

我有一个运行方法,它试图覆盖另一个运行方法。但它没有发生,因为在它传递给运行方法之前我得到了一个“找不到类的异常”。

这是我的带有运行方法的课程

  public class PollingSynchronizer implements Runnable{
   public Collection<KamMessage> incomingQueue,outgoingQueue,fetchedMessages;
   private Connection dbConnection;


/**
 * Constructor. Requires to provide a reference to the Kam message queue
 * 
 * @param incomingMessages reference to message queue
 * @param dbConnection 
 * 
 */
public PollingSynchronizer(Collection<KpiMessage> incomingQueue, Connection dbConnection) {
    super();
    this.incomingQueue = incomingQueue;
    this.dbConnection = dbConnection;
}
private int seqId;
public int getSeqId() {
    return seqId;
}
public void setSeqId(int seqId) {
    this.seqId = seqId;
}



@Override
/**
 * The method which runs Polling action and record the time at which it is done
 * 
 */

      public void run() {
    int seqId = 0;
    while(true) {
        List<KamMessage> list = null;
        try {
            list = fullPoll(seqId);
            if (!list.isEmpty()) {
                seqId = list.get(0).getSequence();
                incomingQueue.addAll(list);
                this.outgoingQueue = incomingQueue;
                System.out.println("waiting 3 seconds");
                System.out.println("new incoming message");
                Thread.sleep(3000);
               //when I debug my execution stops here and throws exception
                MessageProcessor processor = new MessageProcessor() {

                    @Override
                    public void run() {
            new MessageProcessor().generate(outgoingQueue);             
                    }
                };


            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }


    }
}

这是我必须调用才能执行的方法。

    public abstract class MessageProcessor implements Runnable {
private Collection<KpiMessage> fetchedMessages;
private Connection dbConnection;
Statement st = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
private Collection<KpiMessage> outgoingQueue;


public KpiMsg804 MessageProcessor(Collection<KpiMessage> outgoingQueue, Connection
 dbConnection){
    this.outgoingQueue = outgoingQueue;
    this.dbConnection = dbConnection;
    return (KpiMsg804) fetchedMessages;
}

    public Collection<KamMessage> generate(Collection<KamMessage> outgoingQueue)
   {
    while(true){
        try {

            while (rs.next()) {
                KamMessage filedClass = convertRecordsetToPojo(rs);
                outgoingQueue.add(filedClass);

            }

            for (KamMessage pojoClass : outgoingQueue) {
                KamMsg804 updatedValue = createKamMsg804(pojoClass);
                System.out.print(" " + pojoClass.getSequence());
                System.out.print(" " + pojoClass.getTableName());
                System.out.print(" " + pojoClass.getAction());
                System.out.print(" " + updatedValue.getKeyInfo1());
                System.out.print(" " + updatedValue.getKeyInfo2());
                System.out.println(" " + pojoClass.getEntryTime());
            }
            return outgoingQueue;

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

我该如何实现呢?

由于我是新来的,请给出一个不满意的理由。这样我就可以解释我的问题了。

4

1 回答 1

1

尝试这个:

MessageProcessor processor = new MessageProcessor() {

    @Override
    public void run() {
**new MessageProcessor()**.generate(outgoingQueue);             
    }
};
  1. MessageProcessor 是一个抽象类。run 方法中的对象创建应该在编译时失败。
  2. 处理器对象已创建但未使用..您需要使用处理器实例创建一个线程并启动该线程。
于 2014-01-13T12:53:29.060 回答