concept pool in category java

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide.
In the preceding example, the variables str1 and str2 referred to different String objects, even if they were created using the same sequence of characters. In the case of variables str3 and str4, the objects are created and stored in a pool of String objects. Before creating a new object in the pool, Java searches for an String instance with identical contents. When the following line of code executes, no String instance with the value "Harry" is found in the pool of String objects:
String str3 = "Harry";As a result, Java creates a String object with the value "Harry" in the pool of String objects referred to by the variable str3. This action is depicted in figure 5.4.
Figure 5.4 The sequence of steps that executes when Java is unable to locate a String in a pool of String objects
![]()
When the following line of code executes, Java can find a String object with the value "Harry" in the pool of String objects:
String str4 = "Harry";Java doesn’t create a new String object in this case, and the variable str4 refers to the existing String object "Harry". As shown in figure 5.5, both variables str3 and str4 refer to the same String object in the pool of String objects.
Figure 5.5 The sequence of actions that executes when Java locates a String in the pool of String objects.
![]()

This is an excerpt from Manning's book Modern Java in Action: Lambdas, streams, reactive and functional programming.
You may be familiar with the ExecutorService abstraction that was introduced in Java 5. The ExecutorService interface decouples how tasks are submitted and executed. What’s useful in comparison to using threads and Runnable is that by using an Executor-Service you can send a task to a pool of threads and have its result stored in a Future. Don’t worry if this is unfamiliar, we will revisit this topic in later chapters when we discuss concurrency in more detail. For now, all you need to know is that the Callable interface is used to model a task that returns a result. You can see it as an upgraded Runnable:
This method creates an ExecutorService containing nThreads (often called worker threads) and stores them in a thread pool, from which unused threads are taken to run submitted tasks on a first-come, first-served basis. These threads are returned to the pool when their tasks terminate. One great outcome is that it’s cheap to submit thousands of tasks to a thread pool while keeping the number of tasks to a hardware-appropriate number. Several configurations are possible, including the size of the queue, rejection policy, and priority for different tasks.