Are Drools global variables session-bound?

2019-09-03 01:20发布

问题:

When declaring and using global variables within Drools, are globals entirely bound to the session in the sense that once the session is closed, the globals are disposed of too?

Is there some way of storing data in drools memory that can be accessed by numerous sessions at any one time without needing it to be reloaded each time?

回答1:

A DRL global is a POJO, which exists as long as there exists at least one reference to it. After setGlobal, a session keeps one (additional) reference, which is made accessible via the global's name, courtesy of the DRL compiler. If the session is disposed this reference evaporates.

The term "Drools memory" has no significance. There is a session's Working Memory, which is a container for POJOs which have been inserted to become facts; if the session is disposed, these references are discarded. There is the globals. And in DRL code you can access everything that has been imported, including (public) static variables in Java classes.