Rxjava2 OutOfMemoryError

时间:2018-12-11 14:28:34

标签: out-of-memory rx-java2

我经常收到OutOfMemory错误。

示例代码:

Flowable.fromIterable(req.getAllClaims()).filter(Objects::nonNull)
            .flatMap(data -> {
                ClaimStatusCollector collector = statsCollector.get(data.getName());
                collector.setVehicleHelper(vehicleHelper);
                collector.setMedicalHelper(medicalHelper);
                return Flowable.fromCallable(() -> collector.verifyStatus(data)
                        );
            }, 5)
            .blockingIterable().forEach(data -> {
                claims.add(data.blockingFirst());
            });

VehicleClaimStatusCollector.java 
@Override
public Flowable<Claim> verifyStatus(Claim claim)
{
    return Flowable.create(emitter -> {
        try
        {
            //external http call
            emitter.onNext(claim);
        }
        catch (Exception e)
        {
            emitter.onNext(claim);
        }
        emitter.onComplete();
    }, BackpressureStrategy.BUFFER);

}

MedicalClaimStatusCollector.java 
@Override
public Flowable<Claim> verifyStatus(Claim claim)
{
    return Flowable.create(emitter -> {
        try
        {
            //external http call
            emitter.onNext(claim);
        }
        catch (Exception e)
        {
            emitter.onNext(claim);
        }
        emitter.onComplete();
    }, BackpressureStrategy.BUFFER);

}
  

RxCachedThreadScheduler-6034“#6994守护程序prio = 5 os_prio = 31 tid = 0x00007ffcab9ce800 nid = 0x42d07可运行[0x0000700109ffd000]      java.lang.Thread.State:RUNNABLE       在java.net.SocketInputStream.socketRead0(本机方法)

很明显,我们从外部http请求中获取套接字异常。我还在球衣客户端中设置了readtimeout。所有线程都挂在那里,并抛出内存不足错误。

  

java.lang.OutOfMemoryError:无法创建新的本机线程       在java.lang.Thread.start0(本机方法)       在java.lang.Thread.start(Thread.java:714)       在java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950)       在java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1587)       在java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:334)       在java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:549)       在java.util.concurrent.ScheduledThreadPoolExecutor.submit(ScheduledThreadPoolExecutor.java:648)       在io.reactivex.internal.schedulers.NewThreadWorker.scheduleActual(NewThreadWorker.java:146)       在io.reactivex.internal.schedulers.IoScheduler $ EventLoopWorker.schedule(IoScheduler.java:230)       在io.reactivex.Scheduler $ Worker.schedule(Scheduler.java:273)       在io.reactivex.internal.operators.flowable.FlowableSubscribeOn.subscribeActual(FlowableSubscribeOn.java:48)       在io.reactivex.Flowable.subscribe(Flowable.java:13234)       在io.reactivex.Flowable.subscribe(Flowable.java:13170)       在io.reactivex.Flowable.subscribe(Flowable.java:13091)

有人可以帮我吗?

0 个答案:

没有答案