Skip to content

Instantly share code, notes, and snippets.

@ndzj081221130
Created March 10, 2014 01:35
Show Gist options
  • Select an option

  • Save ndzj081221130/9457985 to your computer and use it in GitHub Desktop.

Select an option

Save ndzj081221130/9457985 to your computer and use it in GitHub Desktop.
在jboss集群上部署EJB
stateless Bean
只要在Bean的定义加上@Cluster标记。
stateful Bean一样要加@org.jboss.ejb3.annotation.Clustered标记。默认的策略是FirstAvailable,就是随机选一个节点。
验证stateful bean?以下程序,如果是通过客户端调用的话,请求是会转发给两个不同的节点,但是输出结果总是0?这个stateful该如何体现?应该将state设为static?
设为static后,在同一台机器上的state会按序增加,但是,两台机器之间的数据木有关系,那么stateful如何体现?
node1:0,1,2,3,4
node2:0,1,2
@Stateful
@Clustered
@CacheConfig(maxSize=5000, removalTimeoutSeconds=18000) public class MyBean implements MySessionInt
{
private int state = 0;
public void increment() {
System.out.println("counter: " + (state++)); }
}
关键是客户端调用时
for(i=0~10){
MySessionInt session = (MySessionInt)PortableRemote.narrow(ref,MySessionInt.class);
session.increment();
}
Session EJBs provide remote invocation services. They are clustered based on the **client-side interceptor architecture**.
如果是sticky session的话,那么同一个ip发来的请求,应该会转发到同一个node。
我们可以看到,一次请求中的10都来自与同一个node因此会state递增1-10
再次运行此client时,会在另一个node上运行1-10
下一次就是某个节点上的11-20,以上,证明了jboss-cluster的sticky session。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment