java - 离线同步文件: Upload ArrayList or Upload in a for loop

标签 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-2秒吧。

关于java - 离线同步文件: Upload ArrayList or Upload in a for loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54860765/

相关文章:

超出 Java GC 开销限制 - 需要自定义解决方案

python - 结构化数组排序的性能(numpy)

java - 当独立程序想要退出时,@Scheduled Tasks 使 JVM 保持挂起状态,需要杀死 JVM

java - Android上的音频流

android - 异步下载图片并设置为imageview

javascript - Webpack 使用大型 ES6 模块构建性能缓慢

java - 捕获所有类型的异常编程 Android

java - OSGI:BundleContext.installBundle 线程安全吗?

android - 我对此Android Studio Kotlin程序有疑问:

android - 获取 SQLiteException 并且我不确定是什么原因造成的