Search code examples
javaserverpoolobject-pooling

Questions about ObjectPooling


I am currently working on a simple UDP server for a game. I have already implemented multithreading with the help of a ThreadPoolExecutor. When reading about how to maximize performance I stumbled across ObjectPooling. After some reading I have been left with 3 questions:

1) Will a server program be able to take advantage of an ObjectPool?

2) Which "Objects" should be pooled and which should not?

3) How to create a simple ObjectPool?


Solution

  • Here are answers to your questions,

    1) Will a server program be able to take advantage of an ObjectPool?

    Yes, any object can be pooled. Usually objectpools are used if object creation is heavy operation.

    2) Which "Objects" should be pooled and which should not?

    Any object can be pooled.

    3) How to create a simple ObjectPool?

    You can implement simple pool using apache commons pool. For more information, refer https://commons.apache.org/proper/commons-pool/examples.html

    EDIT: FYI, we implemented objectpool using apache commons pool for connecting to CORBA clients. Connecting to CORBA and creating object was taking more time so we implemented CORBA client pool.