mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 12:59:00 +00:00
32 lines
447 B
Java
32 lines
447 B
Java
package com.iluwatar.object.pool;
|
|
|
|
/**
|
|
*
|
|
* Oliphaunts are expensive to create
|
|
*
|
|
*/
|
|
public class Oliphaunt {
|
|
|
|
private static int counter = 1;
|
|
|
|
private final int id;
|
|
|
|
public Oliphaunt() {
|
|
id = counter++;
|
|
try {
|
|
Thread.sleep(1000);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return String.format("Oliphaunt id=%d", id);
|
|
}
|
|
}
|