2017-02-13 3 views
0

私はEJBを初めて使用しています。ステートレスエンタープライズBeanの機能を理解しようとしています。EJBのステートレスエンタープライズセッションBeanの機能の理解

は、次の例を見てください:ここで

@Stateless 
@LocalBean 
public class FlightService implements Serializable { 

/** 
* Default constructor. 
*/ 
public FlightService() { 
    // TODO Auto-generated constructor stub 
} 
/** 
* @return the id 
*/ 
public Integer getId() { 
    return id; 
} 
/** 
* @param id the id to set 
*/ 
public void setId(Integer id) { 
    this.id = id; 
} 
/** 
* @return the from 
*/ 
public String getFrom() { 
    return from; 
} 
/** 
* @param from the from to set 
*/ 
public void setFrom(String from) { 
    this.from = from; 
} 
/** 
* @return the to 
*/ 
    public String getTo() { 
     return to; 
    } 
    public void setTo(String to) { 
    this.to = to; 
    } 
/** 
* @return the price 
*/ 
    public Integer getPrice() { 
    return price; 
    } 
/** 
* @param price the price to set 
*/ 
    public void setPrice(Integer price) { 
     this.price = price; 
    } 
/** 
* @return the numOfSeats 
*/ 
    public Integer getNumOfSeats() { 
     return numOfSeats; 
    } 
/** 
* @param numOfSeats the numOfSeats to set 
*/ 
    public void setNumOfSeats(Integer numOfSeats) { 
     this.numOfSeats = numOfSeats; 
    } 
    /** 
    * @return the airplaneModel 
*/ 
    public String getAirplaneModel() { 
     return airplaneModel; 
    } 
/* (non-Javadoc) 
* @see java.lang.Object#toString() 
*/ 
@Override 
public String toString() { 
     return "FlightService [id=" + id + ", from=" + from + ", to=" + to + ", price=" + price + ", numOfSeats=" 
      + numOfSeats + ", airplaneModel=" + airplaneModel + "]"; 
} 
/** 
* @param airplaneModel the airplaneModel to set 
*/ 
public void setAirplaneModel(String airplaneModel) { 
    this.airplaneModel = airplaneModel; 
} 
private Integer id =23467; 
private String from="Los Angles"; 
private String to="London"; 
private Integer price=400; 
private Integer numOfSeats=250; 
private String airplaneModel="Boeing 787"; 

} 

は@EJBの依存性の注入が使用されているクラスです。私はなぜ私がいただければ幸いです

"flightService4.setAirplaneModel("cannadian Airlines");" 

どれヘルプに設定された値を取得しています

"flightService.getAirplaneModel()" 

を印刷するとき

@EJB 
private FlightService flightService; 
@EJB 
private FlightService flightService1; 
@EJB 
private FlightService flightService2; 
@EJB 
private FlightService flightService3; 
@EJB 
private FlightService flightService4; 
@EJB 
private FlightService flightService5; 
@EJB 
private FlightService flightService6; 
public FlightDetails() { 
    super(); 
    System.out.println(flightService); 

} 
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 
*/ 
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    // TODO Auto-generated method stub 
    PrintWriter out = response.getWriter(); 
    response.setContentType("text/html"); 
    flightService.setAirplaneModel("Rishanth"); 
    flightService.setFrom("vijaywada"); 
    flightService.setId(1); 
    flightService.setNumOfSeats(4); 
    flightService.setPrice(4); 
    flightService.setTo("hyderabad");  
    flightService4.setAirplaneModel("cannadian Airlines"); 
    out.println(flightService.getAirplaneModel()); 

} 

は、私が理解したいです。

+0

Beanが**ステートレスことになっているので**、すなわちそれは、任意の対話状態を持っていません。そしてBTWは、それがあったとしても、flightService4でsetAirplaneModelを呼び出し、flightServiceでgetAirplaneModelを呼び出しています。 –

+0

@JBNizet私は誤字をお詫び申し上げます。もう一度質問を再訪してください。 –

+0

もう一度、このBeanは**ステートレス**となっています。だから会話の状態を持つことはできません。同じインスタンスによって2つの要求が同時に処理されない限り、コンテナは任意の要求に対して任意のインスタンスを自由に再利用できます。 –

答えて

関連する問題