Difficulty working with Thread in Spring Boot

1

Notice how my controller is

@PostMapping("/anexo")
    public DeferredResult<String> uploadAnexo(@RequestParam("files[]") MultipartFile[] files){
        DeferredResult<String> resultado = new DeferredResult<>();

        // retorno assíncrono
        Thread thread = new Thread(new FotoStorageRunnable(files, resultado));
        thread.start();

        return resultado;
    }

And see how my Thread is

import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.multipart.MultipartFile;

public class FotoStorageRunnable implements Runnable {

    private MultipartFile[] files;
    private DeferredResult<String> resultado;   


    public FotoStorageRunnable(MultipartFile[] files, DeferredResult<String> resultado) {
        this.files = files;
        this.resultado = resultado;
    }

    @Override
    public void run() {
        System.out.println(">>> files: " + files[0].getSize());
        resultado.setResult("ok! esse é o resultado foto recebida");

    }

}

This message should have arrived on the server;

System.out.println(">>> files: " + files[0].getSize());

And these messages should have arrived on the client;

resultado.setResult("ok! esse é o resultado foto recebida");

Neither of these two messages arrived and still generated this error message just below;

Where is it wrong?

    
asked by anonymous 03.04.2018 / 15:21

1 answer

0

The uploadAnexo method sends a parameter of type MultipartFile [] to the constructor of the FotoStorageRunnable class, apparently this parameter is going to null, since the exception thrown is that there is nothing at position 0 of the array.

    
03.04.2018 / 15:36