Resolves checkstyle errors for naked-objects null-object object-mother object-pool observer queue-load-leveling (#1082)
* Reduces checkstyle errors in naked-objects * Reduces checkstyle errors in null-object * Reduces checkstyle errors in object-mother * Reduces checkstyle errors in object-pool * Reduces checkstyle errors in observer * Reduces checkstyle errors in queue-load-leveling
This commit is contained in:
committed by
Ilkka Seppälä
parent
1e76d91929
commit
6ef840f3cf
@ -27,32 +27,30 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* When it is necessary to work with a large number of objects that are particularly expensive to
|
||||
* instantiate and each object is only needed for a short period of time, the performance of an
|
||||
* entire application may be adversely affected. An object pool design pattern may be deemed
|
||||
* desirable in cases such as these.
|
||||
* <p>
|
||||
* The object pool design pattern creates a set of objects that may be reused. When a new object is
|
||||
* needed, it is requested from the pool. If a previously prepared object is available it is
|
||||
*
|
||||
* <p>The object pool design pattern creates a set of objects that may be reused. When a new object
|
||||
* is needed, it is requested from the pool. If a previously prepared object is available it is
|
||||
* returned immediately, avoiding the instantiation cost. If no objects are present in the pool, a
|
||||
* new item is created and returned. When the object has been used and is no longer needed, it is
|
||||
* returned to the pool, allowing it to be used again in the future without repeating the
|
||||
* computationally expensive instantiation process. It is important to note that once an object has
|
||||
* been used and returned, existing references will become invalid.
|
||||
* <p>
|
||||
* In this example we have created {@link OliphauntPool} inheriting from generic {@link ObjectPool}.
|
||||
* {@link Oliphaunt}s can be checked out from the pool and later returned to it. The pool tracks
|
||||
* created instances and their status (available, inUse).
|
||||
*
|
||||
* <p>In this example we have created {@link OliphauntPool} inheriting from generic {@link
|
||||
* ObjectPool}. {@link Oliphaunt}s can be checked out from the pool and later returned to it. The
|
||||
* pool tracks created instances and their status (available, inUse).
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
@ -27,7 +27,8 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Generic object pool
|
||||
* Generic object pool.
|
||||
*
|
||||
* @param <T> Type T of Object in the Pool
|
||||
*/
|
||||
public abstract class ObjectPool<T> {
|
||||
@ -38,7 +39,7 @@ public abstract class ObjectPool<T> {
|
||||
protected abstract T create();
|
||||
|
||||
/**
|
||||
* Checkout object from pool
|
||||
* Checkout object from pool.
|
||||
*/
|
||||
public synchronized T checkOut() {
|
||||
if (available.isEmpty()) {
|
||||
|
@ -26,9 +26,7 @@ package com.iluwatar.object.pool;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
*
|
||||
* Oliphaunts are expensive to create
|
||||
*
|
||||
* Oliphaunts are expensive to create.
|
||||
*/
|
||||
public class Oliphaunt {
|
||||
|
||||
@ -37,7 +35,7 @@ public class Oliphaunt {
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
public Oliphaunt() {
|
||||
id = counter.incrementAndGet();
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.object.pool;
|
||||
|
||||
/**
|
||||
*
|
||||
* Oliphaunt object pool
|
||||
*
|
||||
* Oliphaunt object pool.
|
||||
*/
|
||||
public class OliphauntPool extends ObjectPool<Oliphaunt> {
|
||||
|
||||
|
Reference in New Issue
Block a user