When I am sending HTTP requests to play controller faster then usually, I 
am getting this error:
Execution exception[[CompletionException: java.util.
ConcurrentModificationException: java.util.ConcurrentModificationException]]
Its happening in this part of code:
this.points=layer.points!=null ? layer.points.parallelStream().map(point -> new FPoint(point,messages)).collect(Collectors.toList()) : new ArrayList<>();
Whole stack:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution
exception[[CompletionException: java.util.ConcurrentModificationException:
java.util.ConcurrentModificationException]]
at
play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
at
play.api.http.HttpErrorHandlerExceptions.throwableToUsefulException(HttpErrorHandler.scala)
at
play.http.DefaultHttpErrorHandler.throwableToUsefulException(DefaultHttpErrorHandler.java:169)
at
play.http.DefaultHttpErrorHandler.onServerError(DefaultHttpErrorHandler.java:131)
at
play.core.j.JavaHttpErrorHandlerAdapter$$anonfun$onServerError$1.apply(JavaHttpErrorHandlerAdapter.scala:22)
at
play.core.j.JavaHttpErrorHandlerAdapter$$anonfun$onServerError$1.apply(JavaHttpErrorHandlerAdapter.scala:22)
at
play.core.j.JavaHelpers$$anonfun$invokeWithContext$1.apply(JavaHelpers.scala:142)
at
play.core.j.JavaHelpers$$anonfun$invokeWithContext$1.apply(JavaHelpers.scala:141)
at play.core.j.JavaHelpers$class.withContext(JavaHelpers.scala:153)
at play.core.j.JavaHelpers$.withContext(JavaHelpers.scala:162)
Caused by: java.util.concurrent.CompletionException:
java.util.ConcurrentModificationException:
java.util.ConcurrentModificationException
at
java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
at
java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
at
java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
at
java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
at
java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at
java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
at
scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21)
at
scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at
scala.concurrent.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:63)
Caused by: java.util.ConcurrentModificationException:
java.util.ConcurrentModificationException
at sun.reflect.GeneratedConstructorAccessor78.newInstance(Unknown Source)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at
java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735)
at java.util.stream.ReduceOps$ReduceOp.evaluateParallel(ReduceOps.java:714)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at controllers.liek.api.results.TLayer.<init>(TLayer.java:195)
Caused by: java.util.ConcurrentModificationException: null
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at com.avaje.ebean.common.ModifyIterator.next(ModifyIterator.java:39)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at
java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at
java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:747)
at java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:721)
at java.util.stream.AbstractTask.compute(AbstractTask.java:316)
As ORM I am using Ebean. There is no modification with update , or insert
happening in this part of code only selects.
Controller looks like this:
@Transactional
public Result getLayerByID(){
Messages messages=messagesApi.preferred(request());
Form<FInputData> search=formFactory.form(FInputData.class).
bindFromRequest();
if (search.hasErrors()) {
return badRequest(search.errorsAsJson());
}
FSearchData fSearchData = search.get();
User actualUser = userService.actualUser(ctx());
Result res=null;
if (fSearchData !=null) {
result=layerService.findByID(fSearchData.ID);
}
if (result==null) {
return badRequest(Json.toJson(new TAction(messages.at(
"layer.doesNotExists",fSearchData.ID))));
}
TLayer tResult=result!=null ? new TLayer(result,actualUser ,messages
) : null;
return ok(Json.toJson(tResult!=null ? tResult : new TEmpty() ));
}
layerService.findByID(..) is actually making 20+ selects to database. Where
could be problem?
I am using
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.1.0")
which should support JAVA8 streams...
404NotFound 's gravatar image asked Apr 1 2017 at 15:13 in Play-Framework by 404NotFound

0 Answers