java - Is there any alternative solution when the return value of Future.get() is too large? -


I get large scheduled futures data in the form of return of the get. I believe the Schedule Future can only be returned when it gets () done. So it will always generate "java.util.concurrent.executionexception java.lang.outofmemoryerror java heap space" error on my machine.

Is there any alternative solution that I can split my return in parts when I am using a schedule ExecutionerService? Thank you.

Save your work result to disk, and get method Return that file , which was written as a result.

Note that serialization will not help you to avoid memory problems, because you have the whole result stored in the first place (it does not use more memory than returning it).

You will want to use the "Streaming" approach, where small portions of data are written on disk as soon as they are created.

Similarly, the user in the result should stream the data, smaller parts should be processed in memory, and before reading more, discard the dereference it.

You may also consider using a temporary file for convenience:

  file file = file. CreateTemplate file ("Foo", "Data"); File.deleteOnExit (); // Optional, but safe  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -