无法创建 org.apache.commons.pool2.impl.DefaultEvictionPolicy 类型的 EvictionPolicy 实例
Unable to create EvictionPolicy instance of type org.apache.commons.pool2.impl.DefaultEvictionPolicy
我在应用程序的一部分尝试 save/create/update 数据库中的数据时出现以下错误。该应用程序可以正常工作一段时间,可以说在部署后将近 1-2 小时,但一段时间后开始在更新调用中出现此错误。我正在使用 JPA EclipseLink 实现。
注意:更新调用是使用可完成的未来异步完成的。通话看起来像这样:
CompletableFuture.supplyAsync(() -> {
if (someBean != null) {
try {
someReturnVal = methodCall();
} catch (Exception e) {
log.info("Log with reason: "
+ e.getMessage());
}
}
return someReturnVal;
}).thenAccept(someReturnVal -> {
try {
SomeBean.saveToDB(someReturnVal);
} catch (AccessException e) {
log.info("log with reason: " + e.getMessage());
}
});
SaveToDB 看起来像:
@Transactional
public void SaveToDB(SomeBean arg1) {
try {
em.persist(arg1);
em.flush();
}Catch{
....
}
堆栈跟踪中的错误消息:
java.lang.IllegalArgumentException: Unable to create EvictionPolicy instance of type org.apache.commons.pool2.impl.DefaultEvictionPolicy
at org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:607)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.setConfig(GenericKeyedObjectPool.java:257)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.<init>(GenericKeyedObjectPool.java:111)
at com.**.cloud.runtime.kotyo.persistence.client.pool.GenericKeyedObjectPoolAdapter.<init>(GenericKeyedObjectPoolAdapter.java:25)
at com.**.cloud.runtime.kotyo.persistence.client.pool.managed.PoolableManagedConnectionFactoryAdapter.makeObject(PoolableManagedConnectionFactoryAdapter.java:86)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:861)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)...
...
Caused by: java.lang.ClassNotFoundException: org/apache/commons/pool2/impl/DefaultEvictionPolicy
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forNameFW(Class.java:362)
at java.lang.Class.forName(Class.java:355)
at org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:598)
... 77 common frames omitted
我不知道这里出了什么问题。有人可以帮我吗。
我可以通过使用 Executors 创建自己的 ThreadPoolExecutor 来解决这个问题,如下所示:
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
然后我将这个执行程序传递给我的 CompletableFuture 调用:
CompletableFuture.supplyAsync(() -> { ....
return someReturnVal;
}, executor).thenAccept(someReturnVal -> {
....
});
这解决了我的问题。问题似乎是当新的 CompletableFuture 由 ForkJoinPool.commonPool() 中的任务 运行 异步完成时。
我在应用程序的一部分尝试 save/create/update 数据库中的数据时出现以下错误。该应用程序可以正常工作一段时间,可以说在部署后将近 1-2 小时,但一段时间后开始在更新调用中出现此错误。我正在使用 JPA EclipseLink 实现。
注意:更新调用是使用可完成的未来异步完成的。通话看起来像这样:
CompletableFuture.supplyAsync(() -> {
if (someBean != null) {
try {
someReturnVal = methodCall();
} catch (Exception e) {
log.info("Log with reason: "
+ e.getMessage());
}
}
return someReturnVal;
}).thenAccept(someReturnVal -> {
try {
SomeBean.saveToDB(someReturnVal);
} catch (AccessException e) {
log.info("log with reason: " + e.getMessage());
}
});
SaveToDB 看起来像:
@Transactional
public void SaveToDB(SomeBean arg1) {
try {
em.persist(arg1);
em.flush();
}Catch{
....
}
堆栈跟踪中的错误消息:
java.lang.IllegalArgumentException: Unable to create EvictionPolicy instance of type org.apache.commons.pool2.impl.DefaultEvictionPolicy
at org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:607)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.setConfig(GenericKeyedObjectPool.java:257)
at org.apache.commons.pool2.impl.GenericKeyedObjectPool.<init>(GenericKeyedObjectPool.java:111)
at com.**.cloud.runtime.kotyo.persistence.client.pool.GenericKeyedObjectPoolAdapter.<init>(GenericKeyedObjectPoolAdapter.java:25)
at com.**.cloud.runtime.kotyo.persistence.client.pool.managed.PoolableManagedConnectionFactoryAdapter.makeObject(PoolableManagedConnectionFactoryAdapter.java:86)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:861)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)...
...
Caused by: java.lang.ClassNotFoundException: org/apache/commons/pool2/impl/DefaultEvictionPolicy
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forNameFW(Class.java:362)
at java.lang.Class.forName(Class.java:355)
at org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:598)
... 77 common frames omitted
我不知道这里出了什么问题。有人可以帮我吗。
我可以通过使用 Executors 创建自己的 ThreadPoolExecutor 来解决这个问题,如下所示:
ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
然后我将这个执行程序传递给我的 CompletableFuture 调用:
CompletableFuture.supplyAsync(() -> { ....
return someReturnVal;
}, executor).thenAccept(someReturnVal -> {
....
});
这解决了我的问题。问题似乎是当新的 CompletableFuture 由 ForkJoinPool.commonPool() 中的任务 运行 异步完成时。