1 00:00:01,020 --> 00:00:06,450 The object will batteries and other recreational pattern use for scenarios where creating objects is 2 00:00:06,450 --> 00:00:07,100 expensive. 3 00:00:07,990 --> 00:00:13,090 You can imagine an object billed as a library which checks in and out books whenever there is a demand 4 00:00:13,090 --> 00:00:14,320 for the respective books. 5 00:00:15,340 --> 00:00:20,860 Similarly, the pool will allocate a predefined number of objects and the client will use these objects 6 00:00:20,860 --> 00:00:22,030 depending on its needs. 7 00:00:23,140 --> 00:00:28,540 Some of the advantages of using object pools are objects are cached. 8 00:00:28,690 --> 00:00:30,880 No need to create new objects all the time. 9 00:00:31,520 --> 00:00:34,840 The client will ask for the pool for an object. 10 00:00:35,050 --> 00:00:39,540 The client will ask the pool for an object and one of the cached objects will be returned. 11 00:00:40,360 --> 00:00:42,910 The pattern also enforces object reusability. 12 00:00:43,600 --> 00:00:48,760 Each time when a client does not need an object anymore, it will check out the respective object and 13 00:00:48,760 --> 00:00:51,600 the pool will keep it for reusability purposes. 14 00:00:52,690 --> 00:00:55,210 Some of the downsides of using object pools are. 15 00:00:56,280 --> 00:01:02,460 They tend to be quite complex to implement, usually tread, he said, uncertain when using such a design 16 00:01:02,460 --> 00:01:08,190 pattern and multi threading issues may occur if the implementation is not designed with safety in mind, 17 00:01:09,300 --> 00:01:15,660 usually it requires other design patterns, which can lead to a more difficult to read object. 18 00:01:15,660 --> 00:01:21,170 Polls are often created using the Singleton pattern to facilitate the same instance of the object will 19 00:01:21,190 --> 00:01:22,070 throughout the program. 20 00:01:22,770 --> 00:01:28,050 Also, factory pattern can also be used for creating new objects in the pool as well. 21 00:01:29,250 --> 00:01:34,320 Last point is related to his popularity not being so used by the community due to its complexity. 22 00:01:35,130 --> 00:01:40,770 You will find less articles and explanations on the Internet on how to implement it in Java, especially 23 00:01:40,770 --> 00:01:46,470 if you compare this pattern with more popular operational ones such as factory and builder patterns. 24 00:01:47,430 --> 00:01:50,200 Let's have a look in the code and see how it can be implemented.