简体   繁体   English

使用 web 服务处理大文件

[英]Processing a large file with a web service

I have web service method that is supposed to process a very large file and output several files to the server.我有 web 服务方法应该处理一个非常大的文件和 output 几个文件到服务器。 However, this web service will just timeout and there will be no way for the invoker to get the CREATED status.但是,此 web 服务将超时,调用者将无法获得 CREATED 状态。 I am just wondering whether there is a way to run the processing job (starting a new thread or something) and return the status without waiting for the process to be done.我只是想知道是否有一种方法可以运行处理作业(启动新线程或其他东西)并返回状态而不等待进程完成。

public Response processFile(InputStream inputStream){

   //I want to process the file here
   //but I dont want the invoker to wait for that process to finish
   //I just want the response to be returned right away
   return Response.status(Response.Status.CREATED).build();
}

The file comes from the input stream, right?该文件来自输入stream,对吧? So if you'll send back a CREATED status (effectually closing the connection) you might sever the connection before you receive the entirety of the input file?因此,如果您发送回一个 CREATED 状态(实际上是关闭连接),您可能会在收到整个输入文件之前切断连接?

That's what i thought anyways... In which case you'll just want to set the timeout to a lengthier value.无论如何,这就是我的想法......在这种情况下,您只想将超时设置为更长的值。

If that's not the case, then i guess it would be fine to start a new thread, process everything there in good time and send back the CREATED status.如果不是这种情况,那么我想可以启动一个新线程,及时处理那里的所有内容并发回 CREATED 状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM