`
happyforever82
  • 浏览: 121201 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

关于oc4j在加载和关闭时的处理class

阅读更多

http://download.oracle.com/docs/cd/B25221_04/web.1013/b14433/startclas.htm

 

2 Developing Startup and Shutdown Classes

This chapter provides guidelines on developing startup and shutdown classes that are called after OC4J initializes or before OC4J terminates.

Startup classes can start services and perform functions after OC4J initiates; shutdown classes can terminate these services and perform functions before OC4J terminates. The oc4j.jar must be in the Java CLASSPATH when you compile these classes.

OC4J deploys and executes the OC4J startup and shutdown classes based on configuration of these classes in the server.xml file.

<!---->

Developing Startup Classes

Startup classes are executed only once after OC4J initializes. They are not re-executed every time the server.xml file is touched. Your startup class implements the oracle.j2ee.server.OC4JStartup interface that contains two methods—preDeploy and postDeploy—in which you can implement code for starting services or performing other initialization routines.

  • The preDeploy method executes before any OC4J application initialization.

  • The postDeploy method executes after all OC4J applications initialize.

Each method requires two arguments—a Hashtable that is populated from the configuration and a JNDI Context to which you can bind to process values contained within the Context. Both methods return a String, which is currently ignored.


Note:

It is strongly recommended that you give your startup class a public, no-argument constructor. Otherwise, java.lang.IllegalAccessException may be thrown when OC4J attempts to invoke a member method of this class.

<!---->

Once created, you must configure the startup class within the <startup-classes> element in the server.xml file. You access this file by selecting Advanced Properties on the OC4J home page. Each OC4JStartup class is defined in a single <startup-class> element within the <startup-classes> element. Each <startup-class> defines the following:

  • The name of the class that implements the oracle.j2ee.server.OC4JStartup interface.

  • Whether a failure is fatal. If considered fatal, then when an exception is thrown, OC4J logs the exception and exits. If not considered fatal, then OC4J logs the exception and continues. Default is not fatal.

  • The order of execution where each startup class receives an integer number that designates in what order the classes are executed.

  • The initialization parameters that contain key-value pairs, of type String, which OC4J takes, which are provided within the input Hashtable argument. The names for the key-value pairs must be unique, as JNDI is used to bind each value to its name.

In the <init-library> element in the server.xml file, configure the directory where the startup class resides, or the directory and JAR filename where the class is archived. The path attribute can be fully-qualified or relative to j2ee/home/config.

The configuration for the TestStartup class is contained within a <startup-class> element in the server.xml file. The configuration defines the following:

  • The failure-is-fatal attribute is true, so that an exception causes OC4J to exit.

  • The execution-order is 0, so that this is the first startup class to execute.

  • Two initialization key-value pairs defined, of type String, which will be populated in the Hashtable, of the following:

    "oracle.test.startup" "true"
    "startup.oracle.year" "2002" 
    

    Note:

    The names of the key-value pairs must be unique in all startup and shutdown classes, as JNDI binds the name to its value.

    <!---->

Add the following notation to the server.xml file to define the TestStartup class:

<startup-classes>
  <startup-class classname="TestStartup" failure-is-fatal="true">
    <execution-order>0</execution-order>
    <init-param>
      <param-name>oracle.test.startup</param-name>
      <param-value>true</param-value>
     </init-param>
     <init-param>
      <param-name>startup.oracle.year</param-name>
      <param-value>2002</param-value>
     </init-param>
   </startup-class>
 </startup-classes>

The container provides the two initialization kay-value pairs within the input Hashtable parameter to the startup class.

The following example shows TestStartup, which implements the oracle.j2ee.server.OC4JStartup interface. The preDeploy method retrieves the key-value pairs from the Hashtable and prints them out. The postDeploy method is a null method. The oc4j.jar must be in the Java CLASSPATH when you compile TestStartup.

import oracle.j2ee.server.OC4JStartup;

import javax.naming.*;
import java.util.*;

public class TestStartup implements OC4JStartup {

   //public, no-argument constructor
    public TestStartup() {
    }

    public String preDeploy(Hashtable args, Context context) throws Exception {
        // bind each argument using its name
        Enumeration keys = args.keys();
        while(keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            String value = (String)args.get(key);
            System.out.println("prop: " + key + " value: " + args.get(key));
            context.bind(key, value);
        }

        return "ok";
    }

    public String postDeploy(Hashtable args, Context context) throws Exception {
        return null;
    }
}

Assuming that the TestStartup class is archived in "../app1/startup.jar", modify the <init-library> element in the server.xml file as follows:

<init-library path="../app1/startup.jar" />

When you start OC4J, the preDeploy method is executed before any application is initialized. OC4J populates the JNDI context with the values from the Hashtable. If TestStartup throws an exception, then OC4J exits since the failure-is-fatal attribute was set to TRUE.

<!---->

<!---->

Developing Shutdown Classes

Shutdown classes are executed before OC4J terminates. Your shutdown class implements the oracle.j2ee.server.OC4JShutdown interface that contains two methods—preUndeploy and postUndeploy—in which you can implement code for shutting down services or perform other termination routines.

  • The preUndeploy method executes before any OC4J application terminates.

  • The postUndeploy method executes after all OC4J applications terminate.

Each method requires two arguments—a Hashtable that is populated from the configuration and a JNDI Context to which you can bind to process values contained within the Context.


Note:

It is strongly recommended that you give your shutdown class a public, no-argument constructor. Otherwise, java.lang.IllegalAccessException may be thrown when OC4J attempts to invoke a member method of this class.

<!---->

The implementation and configuration is identical to the shutdown classes as described in "Developing Startup Classes" with the exception that the configuration is defined within the <shutdown-classes> and <shutdown-class> elements and there is no failure-is-fatal attribute. Thus, the configuration for a TestShutdown class would be as follows:

<shutdown-classes>
  <shutdown-class classname="TestShutdown">
    <execution-order>0</execution-order>
    <init-param>
      <param-name>oracle.test.shutdown</param-name>
      <param-value>true</param-value>
     </init-param>
     <init-param>
       <param-name>shutdown.oracle.year</param-name>
       <param-value>2002</param-value>
     </init-param>
   </shutdown-class>
 </shutdown-classes>

Assuming that the TestShutdown class is archived in "../app1/shutdown.jar", add another <init-library> element in the server.xml file as follows:

<init-library path="../app1/shutdown.jar" />
<!----><!---->
分享到:
评论

相关推荐

    oracle下的oc4j配置

    ### Oracle 下的 OC4J 配置入门指南 ...通过以上步骤,您可以顺利地在 Oracle 环境下完成 OC4J 的配置和 WebService 的发布。这些步骤不仅适用于初学者,对于有一定经验的开发人员来说也是很有帮助的。

    oc4j资料包

    - **教程**:可能是逐步指导如何在OC4J上部署和运行Java EE应用的教程,或者如何利用OC4J进行开发的实例教程。 - **示例代码**:这些代码片段或完整的示例项目,可以用来学习OC4J的API用法,以及如何实现特定的功能...

    OC4J的安装配置部署

    - 启动OC4J服务:在`D:\OC4J\j2ee\home`目录下运行`java -jar oc4j.jar`。 - 停止OC4J服务:在新的命令行窗口中执行`java -jar admin.jar rmi://localhost:23791 admin admin-shutdown`。 - 重新启动OC4J服务:同样...

    oc4j(PPT)

    Oracle Containers for J2EE (OC4J) 是Oracle公司提供的一款轻量级、高性能的J2EE应用服务器,它是Oracle应用服务器产品家族的一部分,专为开发和运行小型到中型的J2EE应用程序而设计。OC4J的独特之处在于其轻便的...

    对oc4j 的配置文档

    - **强制关闭OC4J服务**:在另一个命令行窗口中运行`java -jar admin.jar ormi://localhost:23791 admin admin –shutdown force`。 需要注意的是,默认的管理端口为23791,相关配置可以在`d:\oc4j\j2ee\home\...

    oc4j jar包 经测试过可用

    在部署Java应用到OC4J时,开发者通常会将所有依赖的JAR文件(包括XercesImpl和xml-apis)放入OC4J的应用服务器目录或者类路径中,确保运行时能够正确加载到这些库。这样,应用就可以利用这些库的功能来处理XML数据,...

    oracle的oc4j自动部署脚本解决方案

    Oracle的OC4J(Oracle Containers for Java)是Oracle公司提供的一款轻量级Java应用程序服务器,它集成在Oracle Application Server中,用于运行Java EE应用程序。自动部署脚本的创建是为了简化OC4J上的应用部署过程...

    一个全面的OC4J配置文件

    在IT领域,尤其是在Java开发与应用服务器管理方面,Oracle Containers for J2EE(OC4J)作为Oracle的一个关键组件,提供了强大的容器环境用于部署和运行Java应用程序。OC4J配置文件是确保应用服务器正常运作、优化...

    iOS OC 加载动图(gif)

    在本话题中,我们将深入探讨如何在iOS OC项目中加载和播放GIF。 1. **GIF的基本概念** GIF是一种基于LZW压缩算法的无损图像格式,支持多帧动画,每帧之间可以设置不同的延迟时间,组合起来形成动态效果。 2. **...

    如何配置OC4J环境及安装指南

    如何配置OC4J环境及安装指南 如何配置OC4J环境及安装指南

    OC4J里配置数据源

    在OC4J中,首先需要在`application.xml`文件中声明一个`&lt;data-sources&gt;`元素来指定数据源配置文件`data-sources.xml`的位置: ```xml ``` 通常情况下,`application.xml`和`data-sources.xml`文件都位于`j2ee/...

    oc4j 服务器 安装

    - **Secure Sockets Layer (SSL)**:OC4J支持SSL协议,可以在客户端和服务端之间建立加密的通信通道,保护数据不被窃听。 - **Common Secure Interoperability Version 2 (CSIv2)**:这是一种跨平台的安全协议,用于...

    oracle 文档 oracle 文档 oc4j esb

    - **OC4J**: Oracle Container for Java,是Oracle Application Server的一个组成部分,用于支持Java应用程序的部署。 - **ESB**: Enterprise Service Bus,企业服务总线,用于实现不同系统之间的集成和服务交互。 -...

    OC Control LoadingGif(加载动画).zip

    6. **多线程支持**:为了不影响UI的流畅性,加载和显示GIF的操作通常应在后台线程进行,而更新UI则在主线程执行,这涉及到多线程编程的知识。 7. **自定义配置**:为了满足不同场景的需求,工具类可能允许设置动画...

    如何配置OC4J环境及安装指南[参考].pdf

    - 在命令行下运行`java -jar oc4j.jar`来启动OC4J服务。 #### 四、注意事项 - 在进行配置前,请备份原始文件,以防配置错误导致的问题。 - 配置文件中的路径需根据实际情况调整。 - 确保使用的JDK版本与OC4J兼容。...

    OC Control FLAnimatedImage(加载GIF动画).zip

    在iOS开发中,处理GIF动画是一项常见的任务。GIF是一种支持动画的图像格式,广泛用于网络中的动态图片。在Objective-C(OC)中,原生的UIImage类并不支持GIF动画的显示,因此开发者需要借助第三方库来实现。本教程...

    OC Control LoadingAnimation(加载动画).zip

    在iOS开发中,加载动画(Loading Animation)是用户体验设计中不可或缺的一部分,特别是在处理网络请求或者数据加载时。这种视觉反馈可以提升用户对应用性能的认知,同时也能增添界面的互动性。"OC Control Loading...

    OAS中间件---OC4J配置向导

    3. **事务管理**:通过集成Oracle Transaction Manager,OC4J能够支持分布式事务处理,确保数据的一致性和完整性。 4. **集群与负载均衡**:OC4J支持集群部署,可以在多个服务器之间实现负载均衡,提高系统的可用性...

Global site tag (gtag.js) - Google Analytics