java 线程异常退出监控_java-非法的监视器状态异常

如何将轮询线程传递给另一个线程进行处理.

程序执行在控制器类中,该控制器类具有main方法和线程池:

主类控制器

public static void main(String[] args) throws InterruptedException {

RunnableController controller = new RunnableController();

System.out.println(incomingQueue.size());

controller.initializeDb();

controller.initialiseThreads();

System.out.println("Polling");

controller.initialUpdate();

}

具有轮询类的线程的方法

private void initialiseThreads()

{

try {

threadExecutorRead = Executors.newFixedThreadPool(10);

PollingSynchronizer reader = new PollingSynchronizer(incomingQueue,dbConnection);

threadExecutorRead.submit(reader);

}catch (Exception e){

e.printStackTrace();

}

}

具有proccesor类的线程的方法

private void initialUpdate()

{

RunnableController.outgoingQueue = incomingQueue;

if((RunnableController.outgoingQueue)!= null){

try {

threadExecutorFetch = Executors.newFixedThreadPool(10);

MessageProcessor updater = new MessageProcessor(outgoingQueue, dbConnection);

threadExecutorFetch.submit(updater);

DBhandler dbhandler = new DBhandler();

dbhandler.updateDb(getOutgoingQueue());

} catch (Exception e) {

}

}

}

轮询类和控制器类

public void run() {// Thread in the Poller class

int seqId = 0;

while(true) {

List list = null;

try {

list = fullPoll(seqId);

if (!list.isEmpty()) {

seqId = list.get(0).getSequence();

incomingQueue.addAll(list);

this.outgoingQueue = incomingQueue;

System.out.println("waiting");

System.out.println("new incoming message");

while(true){

wait(3000);

notify();

}

}

} catch (Exception e1) {

e1.printStackTrace();

}

}

}

public void run() {// Second thread in the Processor Class

synchronized (this){

RunnableController.setOutgoingQueue(generate(outgoingQueue));

}

notify();

}

}

我的任务和问题是:

1.控制器应同时处理两个线程Poller&处理器,它只应调用轮询器&处理器线程

2.现在我的问题是如何使轮询线程等待3秒并并行通知处理器.

我收到如下错误:

java.lang.IllegalMonitorStateException

at java.lang.Object.wait(Native Method)

at PollingSynchronizer.run(PollingSynchronizer.java:76)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

这里如何实现异步处理?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值