Queue work in ExecutorService newFixedThreadPool ()?

As per this explanation given in the Javadocs , it says the following about

public static ExecutorService newFixedThreadPool (int nThreads)

Creates a thread pool that reuses a fixed number of threads running from a shared unbounded queue. At any given time, no more than nThreads threads will be active processing tasks. If additional tasks are provided when all threads are active, they will wait in the queue as long as the thread is available. If any thread terminates due to a run-time failure before shutting down, a new location will take its place if necessary for subsequent tasks. The threads in the pool will continue to exist as long as it is explicitly disabled.

What queue are they talking about? What if I am not using any queue in my multithreaded application like below:

ExecutorService service;
service=Executors.newFixedThreadPool(5);
while(true){
try {
    s=ss.accept();
//new Thread(new MultithreadedInvocation(s)).start();     
    service.submit(new MultithreadedInvocation(s)).get();
} catch (InterruptedException | ExecutionException ex) {
    ex.printStackTrace();   
}

      

MultithreadedInvocation.java

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
public class MultithreadedInvocation implements Runnable{
//initialize in const'r
private final Socket socket;

public MultithreadedInvocation(Socket s) {
    this.socket=s;
}

@Override
public void run() {
    try {         
        DataInputStream din=new DataInputStream(socket.getInputStream());
        DataOutputStream dout=new DataOutputStream(socket.getOutputStream());
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int str;
        str=din.read();
        String name=din.readUTF();
        System.out.println("Client Name = "+name);
        System.out.println("Actual Client requested for file index "+str+".");
        ClientInfo ci = new ClientInfo();
        ci.ClientName=name;
        ci.ClientFileChoice=str;
        String fileName = new FileMapping().lookupFile(str);
        File tempFile=new File("C:\\Users\\server-3\\Desktop\\List\\"+fileName);
        dout.writeLong(tempFile.length());
        dout.flush();
        din.close();
        dout.close();
        socket.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
}

      

What will happen to my 6th thread in this case, will it be automatically added to this unknown queue

, or the thread pool will terminate and it won't function further?

+3


source to share


1 answer


If you have 5 threads then decide to start a loop that can call up to 30 threads, these processes are queued and wait for the thread to appear.

Your 6th thread will wait until the previous thread completes or is canceled.



Previous message.

+2


source







All Articles