When using aws-sdk-go for file operations, sometimes we need to dynamically set the file size and store it in memory. However, when we use the getObject method to obtain this file, we may find that the acquisition time is longer. This is because in aws-sdk-go, the getObject method is based on the HTTP protocol, and the HTTP protocol requires more time and resources for the transmission of large files. Therefore, when we set the file size dynamically and store it in memory, it may cause the execution time of the getObject method to become longer. In order to reduce the occurrence of this situation, we can consider using other methods that are more suitable for large file transfer, such as segmented downloads or using multi-threaded downloads.
I try to understand ForkJoinPool. I actually don't understand what the fork
method does without a join
and end condition.
If fork
sends a task to be executed in the queue, then why doesn't this code run indefinitely?
import java.util.concurrent.ForkJoinPool; import java.util.concurrent.RecursiveAction; public class Main { public static void main(String[] args) { ForkJoinPool pool = new ForkJoinPool(); pool.invoke(new Test()); } static class Test extends RecursiveAction { @Override protected void compute() { System.out.println(Thread.currentThread().getName()); Test test = new Test(); test.fork(); } } }
The results are always different.
Second question: What happens if you call self fork
in a calculation?
@Override protected void compute() { System.out.println(1); fork(); }
The calculation will be called 1 or 2 times.
Or this:
protected void compute() { System.out.println(1); fork(); join(); }
The calculation will be called multiple times and then stopped.
It does run infinitely, but they daemon threads do not prevent the JVM from shutting down, so they will wait until the main thread has finished (i.e. immediate shutdown) shutdown. Set up an infinite loop that prevents the main thread from completing and you will see your task progressing indefinitely.
public static void main(String[] args) { ForkJoinPool pool = new ForkJoinPool(); pool.invoke(new Test()); while (true) {} } static class Test extends RecursiveAction { @Override protected void compute() { System.out.println(Thread.currentThread().getName()); Test test = new Test(); test.fork(); } }
The above is the detailed content of Why does getObject take longer when file size is set dynamically and stored in memory in aws-sdk-go?. For more information, please follow other related articles on the PHP Chinese website!