浏览 1685 次
锁定老帖子 主题:JBoss启动时通过Seam组件来启用线程
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-12-07
JBoss启动时通过Seam组件来启用线程
样例代码,代码中组件注释说明在下面:
import static org.jboss.seam.annotations.Install.BUILT_IN; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Create; import org.jboss.seam.annotations.Install; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.Startup; import org.jboss.seam.annotations.intercept.BypassInterceptors; @Name("threadAction") @Scope(ScopeType.APPLICATION) @BypassInterceptors @Install(precedence = BUILT_IN) @Startup public class ThreadAction { @Create public void create() { // Start Thread Run Thread t1 = new Thread(new DoSomething()); t1.start(); } class DoSomething implements Runnable { @Override public void run() { while (true) { System.out.println("Thread Run..."); try { Thread.sleep(1000); } catch (Exception e) { } } } } }
1. @Startup注释用来指定Seam组件当环境中某个APPLICATION or SESSION被实例化时,立即实例化组件 Specifies that an instance of this component is created at system initialization time for an application scoped component, or when a session is started for a session scoped component. May only be applied to APPLICATION or SESSION scoped components.
2. @Install(precedence=BUILT_IN)注释指定组件安装的优先级别 指定组件的优先级别。如果具有相同名字的多个组件存在,具有高优先级才被安装, 定义的优先级别是 BUILT_IN:所有内置的Seam组件的优先级别 FRAMEWORK:用于扩展Seam的框架组件的优先级别 APPLICATION:应用程序的组件优先级别(默认优先级) DEPLOYMENT:在特定部署中重载应用程序组件的组件优先级别 MOCK:在测试时MOCK对象使用的优先级别
3. @Create当组件被Seam初始化时,该方法被调用
4. @BypassInterceptors取消在特定组件或一个组件方法上的所有拦截器 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |