Home > Java > Why does getObject take longer when file size is set dynamically and stored in memory in aws-sdk-go?

Why does getObject take longer when file size is set dynamically and stored in memory in aws-sdk-go?

PHPz
Release: 2024-02-08 22:15:33
forward
722 people have browsed it

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.

Question content

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();
        }
    }
}
Copy after login

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();
}
Copy after login

The calculation will be called 1 or 2 times.

Or this:

protected void compute() {
      System.out.println(1);
      fork();
      join();
}
Copy after login

The calculation will be called multiple times and then stopped.

Workaround

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();
    }
}
Copy after login

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!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template