Apache风暴喷口比螺栓计算更快地发出速度导致ConcurrentModificationException

时间:2015-12-27 08:03:44

标签: apache-storm concurrentmodification

这是我的情况。我有一个kafka喷口,每秒喷出一个元组。螺栓将连接到Rserve,需要大约5秒钟来计算结果,然后发出一个元组。 但是螺栓总是得到ConcurrentModificationException然后工人就死了!

public class LagBolt extends BaseRichBolt {

OutputCollector _collector;

public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {
    _collector = outputCollector;
}

public void execute(Tuple tuple) {
    List<Pair> pairs = (List<Pair>) tuple.getValueByField("pairs");
    double[] value = new double[pairs.size()];
    for (int i = 0; i < pairs.size(); i++) {
        value[i] = pairs.get(i).getValue();
    }

    Model model = new Model();
    RConnection rConnection = new RserveConnection().getrConnection();

    // the test() and estimate() need about five seconds to compute
    int d = model.test(rConnection, value);
    int[] ap = model.estimate(rConnection, value, d);
    List<Parameter> parameters = delegate(ap, d);
    rConnection.close();

    _collector.emit(tuple, new Values(parameters));
    _collector.ack(tuple);
}

public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
    outputFieldsDeclarer.declare(new Fields("parameters"));
}

private List<Parameter> delegate(int[] ap, int d){
    int apNum = ap[0];
    List<Parameter> parameters = new ArrayList<Parameter>();

    for(int i = 1; i < 1+apNum; i++){
        for(int j = apNum+1; j < ap.length; j++){
            Parameter parameter = new Parameter(ap[i], d, ap[j]);
            parameters.add(parameter);
        }
    }

    return parameters;
}

这是例外

379632 [Thread-14-Lag] ERROR b.s.util - 异步循环死了! java.lang.RuntimeException:java.util.ConcurrentModificationException         at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:135)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:106)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.disruptor $ consume_batch_when_available.invoke(disruptor.clj:80)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.daemon.executor $ fn__5694 $ fn__5707 $ fn__5758.invoke(executor.clj:819)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.util $ async_loop $ fn__545.invoke(util.clj:479)[storm-core-0.10.0.jar:0.10.0]         在clojure.lang.AFn.run(AFn.java:22)[clojure-1.6.0.jar:?]         在java.lang.Thread.run(Thread.java:745)[?:1.7.0_91] 引起:java.util.ConcurrentModificationException         at java.util.ArrayList $ SubList.checkForComodification(ArrayList.java:1169)〜[?:1.7.0_91]         at java.util.ArrayList $ SubList.listIterator(ArrayList.java:1049)〜[?:1.7.0_91]         在java.util.AbstractList.listIterator(AbstractList.java:299)〜[?:1.7.0_91]         at java.util.ArrayList $ SubList.iterator(ArrayList.java:1045)〜[?:1.7.0_91]         在java.util.AbstractCollection.toString(AbstractCollection.java:450)〜[?:1.7.0_91]         在java.lang.String.valueOf(String.java:2849)〜[?:1.7.0_91]         在java.lang.StringBuilder.append(StringBuilder.java:128)〜[?:1.7.0_91]         在java.util.AbstractCollection.toString(AbstractCollection.java:458)〜[?:1.7.0_91]         at backtype.storm.tuple.TupleImpl.toString(TupleImpl.java:222)〜[storm-core-0.10.0.jar:0.10.0]         在clojure.core $ str.invoke(core.clj:520)〜[clojure-1.6.0.jar:?]         在clojure.core $ str $ fn__3928.invoke(core.clj:524)〜[clojure-1.6.0.jar:?]         在clojure.core $ str.doInvoke(core.clj:526)〜[clojure-1.6.0.jar:?]         在clojure.lang.RestFn.invoke(RestFn.java:516)〜[clojure-1.6.0.jar:?]         at backtype.storm.daemon.executor $ fn__5694 $ tuple_action_fn__5696.invoke(executor.clj:693)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.daemon.executor $ mk_task_receiver $ fn__5615.invoke(executor.clj:436)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.disruptor $ clojure_handler $ reify__5189.onEvent(disruptor.clj:58)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:132)〜[storm-core-0.10.0.jar:0.10.0]         ......还有6个 379677 [Thread-14-Lag] ERROR b.s.d.executor - java.lang.RuntimeException:java.util.ConcurrentModificationException         at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:135)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:106)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.disruptor $ consume_batch_when_available.invoke(disruptor.clj:80)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.daemon.executor $ fn__5694 $ fn__5707 $ fn__5758.invoke(executor.clj:819)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.util $ async_loop $ fn__545.invoke(util.clj:479)[storm-core-0.10.0.jar:0.10.0]         在clojure.lang.AFn.run(AFn.java:22)[clojure-1.6.0.jar:?]         在java.lang.Thread.run(Thread.java:745)[?:1.7.0_91] 引起:java.util.ConcurrentModificationException         at java.util.ArrayList $ SubList.checkForComodification(ArrayList.java:1169)〜[?:1.7.0_91]         at java.util.ArrayList $ SubList.listIterator(ArrayList.java:1049)〜[?:1.7.0_91]         在java.util.AbstractList.listIterator(AbstractList.java:299)〜[?:1.7.0_91]         at java.util.ArrayList $ SubList.iterator(ArrayList.java:1045)〜[?:1.7.0_91]         在java.util.AbstractCollection.toString(AbstractCollection.java:450)〜[?:1.7.0_91]         在java.lang.String.valueOf(String.java:2849)〜[?:1.7.0_91]         在java.lang.StringBuilder.append(StringBuilder.java:128)〜[?:1.7.0_91]         在java.util.AbstractCollection.toString(AbstractCollection.java:458)〜[?:1.7.0_91]         at backtype.storm.tuple.TupleImpl.toString(TupleImpl.java:222)〜[storm-core-0.10.0.jar:0.10.0]         在clojure.core $ str.invoke(core.clj:520)〜[clojure-1.6.0.jar:?]         在clojure.core $ str $ fn__3928.invoke(core.clj:524)〜[clojure-1.6.0.jar:?]         在clojure.core $ str.doInvoke(core.clj:526)〜[clojure-1.6.0.jar:?]         在clojure.lang.RestFn.invoke(RestFn.java:516)〜[clojure-1.6.0.jar:?]         at backtype.storm.daemon.executor $ fn__5694 $ tuple_action_fn__5696.invoke(executor.clj:693)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.daemon.executor $ mk_task_receiver $ fn__5615.invoke(executor.clj:436)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.disruptor $ clojure_handler $ reify__5189.onEvent(disruptor.clj:58)〜[storm-core-0.10.0.jar:0.10.0]         at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:132)〜[storm-core-0.10.0.jar:0.10.0]         ......还有6个

0 个答案:

没有答案