import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger;
public class metodoLeitura implements Runnable {
long inicio;
public Path path;
public String nome;
public Executor pool;
public metodoLeitura(String p,String n, Executor pool){
inicio = System.currentTimeMillis();
path = Paths.get(p);
nome = n;
pool = pool;
}
public void ler_arquivo() {
try {
byte[] texto = Files.readAllBytes(path);
pool.execute(this);
String lendoArquivo = new String(texto);
System.out.println(nome+"\n"+lendoArquivo+"\n");
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void run() {
ler_arquivo();
long fim = System.currentTimeMillis();
long total = (fim - inicio);
System.out.println("Tempo Total: "+total);
}
}
E aqui a classe principal
import java.util.*;
public class metodoleituratest
{
public static void main(String[] args)
{
Thread threadTeste1 = new Thread(new metodoLeitura("arquivo2.txt","1#"));
Thread threadTeste2 = new Thread(new metodoLeitura("arquivo3.txt","2#"));
Thread threadTeste3 = new Thread(new metodoLeitura("arquivo1.txt","3#"));
Thread threadTeste4 = new Thread(new metodoLeitura("arquivo4.txt","3#"));
threadTeste1.start();
threadTeste2.start();
threadTeste3.start();
threadTeste4.start();
}
}