VelocityEngine 是什么包

如题所述

第1个回答  2010-06-30
org.apache.velocity.app.Velocity.类是一个初始化单例的velocity实例的类。

单例模式是一种简单的设计模式,用最简单的话来说,就是让多个类共享一个实例,让他们能够访问到同样的数据。

对比发现:

Velocity类中使用init方法里是使用了RuntimeSingleton.init();

在RuntimeSingleton类中,使用到的运行实例是静态new出来的。

private static RuntimeInstance ri = new RuntimeInstance();

而在org.apache.velocity.app.VelocityEngine类中,并没有一个单例类来初始化,每次都会使用

private RuntimeInstance ri = new RuntimeInstance()

来创建一个新的运行实例,这样就使得每个velocity引擎都会拥有各自的实例,互不干扰。

从RuntimeSingleton类的注释来看:

/**
* This is the Runtime system for Velocity. It is the
* single access point for all functionality in Velocity.
* It adheres to the mediator pattern and is the only
* structure that developers need to be familiar with
* in order to get Velocity to perform.
*
* The Runtime will also cooperate with external
* systems like Turbine. Runtime properties can
* set and then the Runtime is initialized.
*
* Turbine for example knows where the templates
* are to be loaded from, and where the velocity
* log file should be placed.
*/

velocity和外部合作的项目,例如turbine,就使用的这个类来实例化velocity引擎。本回答被提问者采纳