Home Database Mysql Tutorial EJB 3.0 开发指南之定时服务_MySQL

EJB 3.0 开发指南之定时服务_MySQL

Jun 01, 2016 pm 02:06 PM
import timing develop guide document Serve

EJB

  在EJB2.1的规范中需要实现ejbTimeout方法,当然还有ejbPassivate、ejbRemove等方法。在EJB3.0中,只有你想用它们的时候,你才必须创建它们,否则不必实现。

  这个例子主要有5个文件,这个例子的Bean是一个无状态会话Bean:

  NewsTimer.java:业务接口。

  NewsTimer.java:业务实现类。将来我们开发的EJB也都是这样命名(在接口名上加上Bean)。

  Client.java:测试EJB的客户端类。

  jndi.properties:jndi属性文件,提供访问jdni的基本配置属性。

  Build.xml:ant 配置文件,用以编译、发布、测试、清除EJB。

  下面针对每个文件的内容做一个介绍。

  NewsTimer.java

  package com.kuaff.ejb3.schedule;
  import javax.ejb.Remote;
  @Remote

  public interface NewsTimer
  {
  public void fiveNews();
  }

  这个接口定义了fiveNews方法,如果这个方法被调用,5分钟后将往控制台上输出一条新闻。

  你不必配置它的JNDI名称,也不必写它的配置文件。在JBOSS实现的EJB3.0中,你不必写任何的EJB部署文件和jboss部署文件。JBOSS默认使用接口的全称作为它的JNDI名。在上面的例子中,它的全称可以通过NewsTimerclass.forName()得到。

  NewsTimerBean.java

  package com.kuaff.ejb3.schedule;
  import java.util.Date;
  import javax.ejb.Inject;
  import javax.ejb.SessionContext;
  import javax.ejb.Stateless;
  import javax.ejb.Timer;

  @Stateless

  public class NewsTimerBean implements NewsTimer
  {
  private @Inject SessionContext ctx;
  public void fiveNews()
  {
  ctx.getTimerService().createTimer(new Date(new Date().getTime() + 300000), "子虚乌有电视台5分钟新闻栏目:现在过5分钟,又到即时新闻节目的时间了。");
  }

  public void ejbTimeout(Timer timer)
  {
  System.out.printf("时间到:%n%s%n" , timer.getInfo());
  timer.cancel();
  }
  }

  Client.java

  package com.kuaff.ejb3.schedule;

  import javax.naming.InitialContext;
  import javax.naming.NamingException;

  public class Client
  {
  public static void main(String[] args) throws NamingException
  {
  InitialContext ctx = new InitialContext();
  NewsTimer timer = (NewsTimer) ctx.lookup(NewsTimer.class.getName());
  timer.fiveNews();
  }
  }

  这个类用来测试我们发布的计数器EJB。首先通过

  ctx = new InitialContext();

  得到上下文,然后通过lookup查找NewsTimer,然后启动计时。。

  请运行{$JBOSS_HOME}/bin目录下的run.bat: run

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. What to do if the 0x80004005 error code appears. The editor will teach you how to solve the 0x80004005 error code. Mar 21, 2024 pm 09:17 PM

When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

Setting up Chinese with VSCode: The Complete Guide Setting up Chinese with VSCode: The Complete Guide Mar 25, 2024 am 11:18 AM

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Will setting up scheduled sending on Douyin affect traffic? What is the tutorial on how to set a timer to turn off playback? Will setting up scheduled sending on Douyin affect traffic? What is the tutorial on how to set a timer to turn off playback? Mar 21, 2024 pm 04:51 PM

With the popularity of Douyin, more and more users and companies have begun to pay attention to Douyin marketing. During the operation process, some users asked, will Douyin’s scheduled sending affect traffic? This article will discuss this issue and share a tutorial on how to set a timer to turn off playback on Douyin. 1. Will setting up scheduled sending on Douyin affect traffic? Douyin’s scheduled sending feature allows users to choose to automatically post at a specific time when creating a video. Regarding the impact of this feature on traffic, the official has not yet provided a clear explanation. Based on actual operational experience and analysis, it can be concluded that the impact of the scheduled sending function on traffic can be ignored. The core of Douyin traffic lies in the quality of video content and user interaction, not just the release time. Great content and engaging interactions are key to attracting users’ attention. when

Create and run Linux ".a" files Create and run Linux ".a" files Mar 20, 2024 pm 04:46 PM

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension ".a" have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run ".a" files. This article will introduce how to comprehensively install and configure the Linux ".a" file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux ".a" file. What is L

Is PHP front-end or back-end in web development? Is PHP front-end or back-end in web development? Mar 24, 2024 pm 02:18 PM

PHP belongs to the backend in web development. PHP is a server-side scripting language, mainly used to process server-side logic and generate dynamic web content. Compared with front-end technology, PHP is more used for back-end operations such as interacting with databases, processing user requests, and generating page content. Next, specific code examples will be used to illustrate the application of PHP in back-end development. First, let's look at a simple PHP code example for connecting to a database and querying data:

See all articles