Skip to content

Commit

Permalink
bug fix for idle time calculation of pool object (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkata-kishore authored Jan 15, 2025
1 parent f0981a4 commit d1c3d58
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ msbuild.wrn
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr

# CMake
cmake-build-*/
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>simple-object-pool</artifactId>
<version>2.3.1</version>
<version>2.3.2</version>
<packaging>jar</packaging>

<properties>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/today/bonfire/oss/sop/PooledObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*/
public class PooledObject<T extends PoolObject> {
private final T object;
private final long creationTime;
private volatile long lastBorrowedTime;
private volatile long idleFromTime;
private final long creationTime;
private volatile long lastBorrowedTime;
private volatile long idleFromTime;
private volatile boolean broken;
private volatile boolean borrowed;
private long timesBorrowed;
private long timesBorrowed;

/**
* Creates a new PooledObject wrapping the given object with a specified ID.
Expand All @@ -29,6 +29,7 @@ public class PooledObject<T extends PoolObject> {
this.object = object;
object.setEntityId(id);
this.creationTime = System.currentTimeMillis();
this.idleFromTime = this.creationTime;
this.borrowed = false;
this.broken = false; // Initialize broken state
}
Expand Down Expand Up @@ -101,7 +102,7 @@ Long id() {
* This method should be called when the object is taken from the pool.
*/
void borrow() {
borrowed = true;
borrowed = true;
lastBorrowedTime = System.currentTimeMillis();
timesBorrowed++;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/today/bonfire/oss/sop/SimpleObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ private void evictionRun() {
"created {} ago, " +
"idling for {}ms " +
"used {} time(s), ",
pooledObject.id(), Duration.ofMillis(System.currentTimeMillis() - pooledObject.creationTime()), pooledObject.idlingTime(), pooledObject.borrowCount());
pooledObject.id(),
Duration.ofMillis(System.currentTimeMillis() - pooledObject.creationTime()),
pooledObject.idlingTime(), pooledObject.borrowCount());
} catch (Exception e) {
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
}
Expand Down

0 comments on commit d1c3d58

Please sign in to comment.