离线同步文件:上传ArrayList或for循环上传

时间:2019-02-25 06:41:58

标签: java android performance asynchronous upload

我基本上是一名Java开发人员,只具有有关Android开发的基本信息。我已经开发了一个可以接受文件和其他一些参数的Web端点。 Java代码是

@RequestMapping(path = "/api/beneficiary/initial/inspection/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String uploadInitialInspectionPhoto(@RequestParam(value = "uploadImg") MultipartFile file,
        @RequestParam("hdId") Long hdId, @RequestParam("toRegId") String toRegId,
        @RequestParam(value = "remark", required = false) String remark,
        @RequestParam(value="latitude")String latitude,
        @RequestParam(value="longitude")String longitude) {
//.... Method Code
}

我的Android开发人员说,在异步后台线程上载10个文件需要10分钟,因为它必须访问URL 10次。她建议我将API更改为接受ArrayList。即将界面更改为

@RequestMapping(path = "/api/beneficiary/initial/inspection/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String uploadInitialInspectionPhoto(@RequestParam(value = "uploadImg") MultipartFile[] files,
        @RequestParam("hdId") Long[] hdIds, @RequestParam("toRegId") String[] toRegIds,
        @RequestParam(value = "remark", required = false) String[] remarks,
        @RequestParam(value="latitude")String[] latitudes,
        @RequestParam(value="longitude")String[] longitudes) {
     for (int idx =  0; idx < hdIds.length; idx++)
     {
        //... Same code as in current method
        officerSvc.save(.....)
     }
} 

请注意复数形式和[]

我的基本问题是:是否建议将api更改为接受ArrayList / Array而不是单个实例,以便凭借其优点提高上载的性能?事实还是虚构?

1 个答案:

答案 0 :(得分:1)

是的,它将节省创建客户端和服务器之间的连接的时间。 但这不是很多,大概1-2秒。