Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to implement a Object pool in java

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ranchers,
If I want to implement a Object pool in java using the built in data structures and the pros and cons, how do I go ahead and implement one.

Here is my approach. But I am sure there are many ways to implement and which is more efficient.

1. Implement using a queue. Its better to use arrays in the background and expose it via an Interface.
2. To implement using the LInkedList as it implements the Queue interface internally but exposing through an Interface which has only get and return method which will delegate to the internal linkedlist to return the first in element and to put it back to the Queue.

3. Implement using a PriorityQueue.

Any better way to do this in Java?

Regards,
Pradeep
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, a LinkedList already is a Queue. So that makes the first two the same thing. As for a PriorityQueue, I would only use that if there was some reason to put the objects in the pool into a certain sequence. Usually there isn't any such reason in an object pool, so I normally wouldn't consider that.
 
Pradeep Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Are there any other data structures which is an optimum for implementation apart from Queue?
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!