avoid deadlock with stateful EJB

S

sk

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 ..........!!!!";
}
 
W

Wesley Hall

sk said:
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++'.
 
J

John Ersatznom

Wesley said:
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. ;)
 
W

wesley.hall

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:)
 
M

M D

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?
 
A

Alfred

sk said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top