编程语言
首页 > 编程语言> > java – Android上的RequestFactory缓慢

java – Android上的RequestFactory缓慢

作者:互联网

我正在使用带引擎和android的RequestFactory.它一直很好用,但是当我检索任何大小的对象列表(大约400个)时,它的响应非常延迟.似乎数据的传输发生得相当快(约4秒),但是直到很久以后(1-2分钟或更长时间)才进行onSuccess()回调.我猜这可能是在requestfactory中解析的速度慢.我的对象只是POJO,包含大约10个字段的文本和长整数.

我的问题是有没有人遇到这个?任何人都有更有效的方法从android中快速获取大量的数据?

更新:当使用RF与许多实体(3000)时,我也遇到了outofmemoryerrors.我使用GSON lib切换到直接json并且解析更快并且还没有遇到内存问题.

我通过电汇发送的具体实体如下(我正在使用Objectify).

@Cached
@Entity
public class InterestPoint
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long groupId;
private String more, data;
@Unindexed
private int lat, longi;
@Unindexed
private String address, city, state;
@Unindexed
private int num1, num2, num3;
@Unindexed
private int num4,num5,num6;
@Unindexed
private String name;
@Unindexed
private int moreData;
@Unindexed
private String notes;
}

解决方法:

添加到作者对问题的描述

我们正在检索8个相对较小的对象,每个对象都有一到四个很小的子对象:

这是从服务器返回响应后的堆栈示例,在org.json包或com.google.web.bindery中超过一分钟,我们的CPU使用率很高:

java.lang.AbstractStringBuilder append0 AbstractStringBuilder.java  143 false   
java.lang.StringBuilder append  StringBuilder.java  125 false   
org.json.JSONStringer   string  JSONStringer.java   344 false   
org.json.JSONStringer   value   JSONStringer.java   252 false   
org.json.JSONObject quote   JSONObject.java 713 false   
com.google.web.bindery.autobean.shared.impl.StringQuoter    quote   StringQuoter.java   69  false   
com.google.web.bindery.autobean.shared.impl.StringQuoter    create  StringQuoter.java   50  false   
com.google.web.bindery.autobean.shared.ValueCodex$Type$13   encode  ValueCodex.java 193 false   
com.google.web.bindery.autobean.shared.ValueCodex   encode  ValueCodex.java 315 false   
com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$ValueCoder    extractSplittable   AutoBeanCodexImpl.java  500 false   
com.google.web.bindery.autobean.shared.impl.AbstractAutoBean    setProperty AbstractAutoBean.java   277 false   
com.google.web.bindery.autobean.vm.impl.ProxyAutoBean   setProperty ProxyAutoBean.java  253 false   
com.google.web.bindery.autobean.vm.impl.BeanPropertyContext set BeanPropertyContext.java    44  false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$3  visitValueProperty  AbstractRequestContext.java 910 false   
com.google.web.bindery.autobean.vm.impl.ProxyAutoBean   traverseProperties  ProxyAutoBean.java  289 false   
com.google.web.bindery.autobean.shared.impl.AbstractAutoBean    traverse    AbstractAutoBean.java   166 false   
com.google.web.bindery.autobean.shared.impl.AbstractAutoBean    accept  AbstractAutoBean.java   101 false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext    processReturnOperation  AbstractRequestContext.java 879 false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext    processReturnOperations AbstractRequestContext.java 1215    false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext    access$600  AbstractRequestContext.java 76  false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect processPayload  AbstractRequestContext.java 347 false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5  onTransportSuccess  AbstractRequestContext.java 1108    false   
com.whichfestival.AndroidRequestTransport   send    AndroidRequestTransport.java    68  false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext    doFire  AbstractRequestContext.java 1102    false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext    fire    AbstractRequestContext.java 569 false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequest   fire    AbstractRequest.java    54  false   
com.google.web.bindery.requestfactory.shared.impl.AbstractRequest   fire    AbstractRequest.java    59  false   
com.whichfestival.FetchTopService   getEvents   FetchTopService.java    99  false   
com.whichfestival.FetchTopService   onHandleIntent  FetchTopService.java    56  false   
android.app.IntentService$ServiceHandler    handleMessage   IntentService.java  59  false   
android.os.Handler  dispatchMessage Handler.java    99  false   
android.os.Looper   loop    Looper.java 130 false   
android.os.HandlerThread    run HandlerThread.java  60  false   

我们看到GC大约25次:

11-16 22:30:28.464: D/dalvikvm(416): GC_CONCURRENT freed 930K, 51% free 3321K/6727K, external 1654K/2137K, paused 15ms+10ms

11-16 22:30:33.605: D/dalvikvm(416): GC_CONCURRENT freed 515K, 49% free 3452K/6727K, external 1654K/2137K, paused 10ms+13ms

11-16 22:30:37.554: D/dalvikvm(416): GC_CONCURRENT freed 638K, 49% free 3497K/6727K, external 1654K/2137K, paused 11ms+10ms

11-16 22:30:43.424: D/dalvikvm(416): GC_CONCURRENT freed 681K, 47% free 3572K/6727K, external 1654K/2137K, paused 6ms+9ms

所有约15个小pojos …将不胜感激任何帮助.绝对不顾一切地解决这个问题.

标签:java,android,requestfactory
来源: https://codeday.me/bug/20190704/1379084.html