Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > avoid deadlock with stateful EJB

Reply
Thread Tools

avoid deadlock with stateful EJB

 
 
sk
Guest
Posts: n/a
 
      12-21-2006
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 ..........!!!!";
}


 
Reply With Quote
 
 
 
 
Wesley Hall
Guest
Posts: n/a
 
      12-21-2006
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 ..........!!!!";
> }
>
>

 
Reply With Quote
 
 
 
 
John Ersatznom
Guest
Posts: n/a
 
      12-21-2006
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.
 
Reply With Quote
 
wesley.hall@gmail.com
Guest
Posts: n/a
 
      12-21-2006

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

 
Reply With Quote
 
M D
Guest
Posts: n/a
 
      12-21-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
>
>> > 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 )
>


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?




 
Reply With Quote
 
Alfred
Guest
Posts: n/a
 
      12-22-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to generate "ejb-jar.xml" from EJB class (source)? "ejb-jar.xml" appserver independent? Raymond Schanks Java 0 08-03-2010 08:21 AM
EJB 3 Stateful Session Bean create method Giovanni Azua Java 0 05-03-2009 02:49 PM
avoid deadlock for EJB M D Java 5 12-22-2006 04:33 PM
EJB Stateful Session Beans Sachin Java 0 11-04-2005 06:18 AM
Stateful NAT failover = yes. Stateful CBAC failover = ???? Alec Waters Cisco 0 06-09-2004 01:38 PM



Advertisments