Skip to content

Commit d1c3d58

Browse files
bug fix for idle time calculation of pool object (#7)
1 parent f0981a4 commit d1c3d58

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

.gitignore

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ msbuild.wrn
130130
# When using Gradle or Maven with auto-import, you should exclude module files,
131131
# since they will be recreated, and may cause churn. Uncomment if using
132132
# auto-import.
133-
.idea/artifacts
134-
.idea/compiler.xml
135-
.idea/jarRepositories.xml
136-
.idea/modules.xml
137-
.idea/*.iml
138-
.idea/modules
139-
*.iml
140-
*.ipr
133+
.idea/artifacts
134+
.idea/compiler.xml
135+
.idea/jarRepositories.xml
136+
.idea/modules.xml
137+
.idea/*.iml
138+
.idea/modules
139+
*.iml
140+
*.ipr
141141

142142
# CMake
143143
cmake-build-*/

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212

1313
<artifactId>simple-object-pool</artifactId>
14-
<version>2.3.1</version>
14+
<version>2.3.2</version>
1515
<packaging>jar</packaging>
1616

1717
<properties>

src/main/java/today/bonfire/oss/sop/PooledObject.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*/
1111
public class PooledObject<T extends PoolObject> {
1212
private final T object;
13-
private final long creationTime;
14-
private volatile long lastBorrowedTime;
15-
private volatile long idleFromTime;
13+
private final long creationTime;
14+
private volatile long lastBorrowedTime;
15+
private volatile long idleFromTime;
1616
private volatile boolean broken;
1717
private volatile boolean borrowed;
18-
private long timesBorrowed;
18+
private long timesBorrowed;
1919

2020
/**
2121
* Creates a new PooledObject wrapping the given object with a specified ID.
@@ -29,6 +29,7 @@ public class PooledObject<T extends PoolObject> {
2929
this.object = object;
3030
object.setEntityId(id);
3131
this.creationTime = System.currentTimeMillis();
32+
this.idleFromTime = this.creationTime;
3233
this.borrowed = false;
3334
this.broken = false; // Initialize broken state
3435
}
@@ -101,7 +102,7 @@ Long id() {
101102
* This method should be called when the object is taken from the pool.
102103
*/
103104
void borrow() {
104-
borrowed = true;
105+
borrowed = true;
105106
lastBorrowedTime = System.currentTimeMillis();
106107
timesBorrowed++;
107108
}

src/main/java/today/bonfire/oss/sop/SimpleObjectPool.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ private void evictionRun() {
165165
"created {} ago, " +
166166
"idling for {}ms " +
167167
"used {} time(s), ",
168-
pooledObject.id(), Duration.ofMillis(System.currentTimeMillis() - pooledObject.creationTime()), pooledObject.idlingTime(), pooledObject.borrowCount());
168+
pooledObject.id(),
169+
Duration.ofMillis(System.currentTimeMillis() - pooledObject.creationTime()),
170+
pooledObject.idlingTime(), pooledObject.borrowCount());
169171
} catch (Exception e) {
170172
log.warn("Failed to destroy object with id {} in pool - {}", pooledObject.id(), config.poolName(), e);
171173
}

0 commit comments

Comments
 (0)