The RequestTask class

The RequestTask class is the intermediary between the ConcurrentServer class, which connects to the clients, and the Executor class, which executes concurrent tasks. It opens the socket with the client, reads the query data, creates the adequate command, and sends it to the executor.

It uses some internal attributes:

  • A LinkedBlockingQueue where the ConcurrentServer class stores the client sockets
  • A ServerExecutor to execute the commands as concurrent tasks
  • A ConcurrentHashMap to store the Future objects associated with the tasks

The constructor of the class initializes all these objects.

public class RequestTask implements Runnable { private LinkedBlockingQueue<Socket> pendingConnections; private ServerExecutor executor ...

Get Mastering Concurrency Programming with Java 9 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.