avoid deadlock with stateful EJB

Discussion in 'Java' started by sk, Dec 21, 2006.

  1. sk

    sk Guest

    I have the following function in a stateful ejb. When I call this function
    will display
    "hello" at the server console. What I want to know is when I exist from the
    client
    by cutting my network cable is there any way to know if the client has
    exited from
    the server? Currently it keeps displaying the hello line without stopping.


    public String SayHello() {
    //TODO implement SayHello\
    try{
    java.util.GregorianCalendar t = new
    java.util.GregorianCalendar();
    System.out.println( "111 Statefull Timer started "+
    t.getTime().toString());
    for( int i = 0; i < 10; i--){
    System.out.println("hello");
    }

    }catch(Exception e){
    e.printStackTrace();
    }

    return "Say Hello ..........!!!!";
    }
     
    sk, Dec 21, 2006
    #1
    1. Advertising

  2. sk

    Wesley Hall Guest

    sk wrote:
    > I have the following function in a stateful ejb. When I call this function
    > will display
    > "hello" at the server console. What I want to know is when I exist from the
    > client
    > by cutting my network cable is there any way to know if the client has
    > exited from
    > the server? Currently it keeps displaying the hello line without stopping.


    It does this because of a bug in the code...

    "for( int i = 0; i < 10; i--)"

    You are saying "start i at 0, continue until i is bigger than 10,
    subtract 1 from i each iteration".

    i=0
    i=-1
    i=-2

    Bingo... infinate loop.

    Try changing the last part of your for loop to 'i++'.

    > public String SayHello() {
    > //TODO implement SayHello\
    > try{
    > java.util.GregorianCalendar t = new
    > java.util.GregorianCalendar();
    > System.out.println( "111 Statefull Timer started "+
    > t.getTime().toString());
    > for( int i = 0; i < 10; i--){
    > System.out.println("hello");
    > }
    >
    > }catch(Exception e){
    > e.printStackTrace();
    > }
    >
    > return "Say Hello ..........!!!!";
    > }
    >
    >
     
    Wesley Hall, Dec 21, 2006
    #2
    1. Advertising

  3. Wesley Hall wrote:
    > sk wrote:
    >
    >>I have the following function in a stateful ejb. When I call this function
    >>will display
    >>"hello" at the server console. What I want to know is when I exist from the
    >>client
    >>by cutting my network cable is there any way to know if the client has
    >>exited from
    >>the server? Currently it keeps displaying the hello line without stopping.

    >
    >
    > It does this because of a bug in the code...
    >
    > "for( int i = 0; i < 10; i--)"
    >
    > You are saying "start i at 0, continue until i is bigger than 10,
    > subtract 1 from i each iteration".
    >
    > i=0
    > i=-1
    > i=-2
    >
    > Bingo... infinate loop.


    Wait 2147483647 more iterations or so, actually, and it will actually
    stop. ;)
     
    John Ersatznom, Dec 21, 2006
    #3
  4. sk

    Guest


    > > Bingo... infinate loop.

    >
    > Wait 2147483647 more iterations or so, actually, and it will actually
    > stop. ;)


    True, true. Not infinate I guess. Still you can fix it by changing the
    loop counter to long. Even then it wouldn't be infinate, but by the
    time it overflowed you would be dead and it would be someone else's
    problem :eek:)
     
    , Dec 21, 2006
    #4
  5. sk

    M D Guest

    <> wrote in message
    news:...
    >
    >> > Bingo... infinate loop.

    >>
    >> Wait 2147483647 more iterations or so, actually, and it will actually
    >> stop. ;)

    >
    > True, true. Not infinate I guess. Still you can fix it by changing the
    > loop counter to long. Even then it wouldn't be infinate, but by the
    > time it overflowed you would be dead and it would be someone else's
    > problem :eek:)
    >


    I just made this program to make dead lock on purpose.

    So there is no way to stop this process until i stop the server?
     
    M D, Dec 21, 2006
    #5
  6. sk

    Alfred Guest

    sk wrote:
    > I have the following function in a stateful ejb. When I call this function
    > will display
    > "hello" at the server console. What I want to know is when I exist from the
    > client
    > by cutting my network cable is there any way to know if the client has
    > exited from
    > the server? Currently it keeps displaying the hello line without stopping.
    > ....


    You do not have any ideas what an EJB is.

    Alfred
     
    Alfred, Dec 22, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sachin

    EJB Stateful Session Beans

    Sachin, Nov 4, 2005, in forum: Java
    Replies:
    0
    Views:
    375
    Sachin
    Nov 4, 2005
  2. Dean Stevens

    How to avoid deadlock?

    Dean Stevens, Sep 1, 2003, in forum: C Programming
    Replies:
    24
    Views:
    1,349
    Markus Elfring
    Sep 18, 2003
  3. M D

    avoid deadlock for EJB

    M D, Dec 21, 2006, in forum: Java
    Replies:
    5
    Views:
    562
  4. Giovanni Azua
    Replies:
    0
    Views:
    661
    Giovanni Azua
    May 3, 2009
  5. Raymond Schanks
    Replies:
    0
    Views:
    661
    Raymond Schanks
    Aug 3, 2010
Loading...

Share This Page