[jboss-user] [Clustering/JBoss] - Re: Loadbalancing and clustering JBOSS using Apache Http ser
yugantshah
do-not-reply at jboss.com
Tue Mar 11 11:16:53 EDT 2008
Hello,
I am running the simple ejb3 clustering example.
Where in I have a jsp that calls the bean.This call is in a for loop with time lag in it.
The bean return the String message that is printed by the jsp on the console.
I am attaching the code for HelloWorldBean.java
| package com;
|
| import javax.annotation.PostConstruct;
| import javax.annotation.PreDestroy;
| import javax.ejb.Local;
| import javax.ejb.PostActivate;
| import javax.ejb.PrePassivate;
| import javax.ejb.Remote;
| import javax.ejb.Stateful;
| import javax.ejb.Stateless;
|
| import org.jboss.annotation.ejb.Clustered;
| import org.jboss.annotation.ejb.LocalBinding;
| import org.jboss.annotation.ejb.RemoteBinding;
|
|
| @Stateless
| @Remote(HelloWorldInterface.class)
| @RemoteBinding(jndiBinding="ejb/local/HelloWorldBean")
| @Clustered
| public class HelloWorldBean {
|
| public String getMessage(){
| for(int k=0;k<10;k++) {
| Object a = new Object();
| System.out.println("YUGANT Bean:"+k);
| try {
| Thread.sleep(500);
| } catch (InterruptedException e) {
| // TODO Auto-generated catch block
| e.printStackTrace();
| }
| }
| return "Say Hello";
| }
| @PreDestroy
| public void preDestroy(){
| System.out.println("HelloWorldBean:preDestroy:");
| }
| @PostActivate
| public void postActivate(){
| System.out.println("HelloWorldBean:postActivate:");
| }
| @PrePassivate
| public void prePassivate(){
| System.out.println("HelloWorldBean:prePassivate:");
| }
| @PostConstruct
| public void postConstruct(){
| System.out.println("HelloWorldBean:PostConstruct:");
| }
| }
|
|
|
The code for Business interface class is
| package com;
|
| public interface HelloWorldInterface {
| public String getMessage();
| }
|
The jsp code is :
|
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
| pageEncoding="ISO-8859-1"%>
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
| <%@page import="java.util.Properties"%>
| <%@page import="javax.naming.Context"%>
| <%@page import="javax.naming.InitialContext"%>
| <%@page import="com.HelloWorldInterface"%>
| <html>
| <head>
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
| <title>Insert title here</title>
| </head>
| <body>
| <%
|
| Context ctx = new InitialContext();
| HelloWorldInterface fcs = (HelloWorldInterface)ctx.lookup("ejb/local/HelloWorldBean");
| int k = 0;
| while(k<10) {
| System.out.println(fcs.getMessage()+":"+k);
| Thread.sleep(500);
| k++;
| }
| %>
|
Thanks,
Yugant Shah.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4135658#4135658
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4135658
More information about the jboss-user
mailing list