Class ClassInstanceCache

java.lang.Object
org.optaplanner.core.impl.solver.ClassInstanceCache

public final class ClassInstanceCache extends Object
Exists so that particular user-provided classes, which are instantiated by OptaPlanner from SolverConfig, only ever have one instance. Each solver instance needs to get a fresh instance of this class, so that solvers can not share state between them.

Case in point, NearbyDistanceMeter. If two places in the config reference the same implementation of this interface, we can be sure that they represent the same logic. And since it is us who instantiate them and they require no-arg constructors, we can be reasonably certain that they will not contain any context-specific state. Therefore it is safe to have all of these references served by a single instance, allowing for all sorts of beneficial caching. (Such as, in this case, nearby distance matrix caching across the solver.)

See Also: