Bookmark Topic Watch Topic
  • New Topic

jsp/servlet executes business method

 
Olexiy Prokhorenko
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello guys,

I have few JSP/Servlet's. Also, I have class with business methods, and my JSP/Servlets are invoking these business methods. These business methods could make calls to EJB, or access databases via JDBC, etc., etc., etc.

What is the easiest and proper way to make sure, that after invoking such business method our JSP/Servlet will wait for N seconds, and if method will not finish it's execution, so JSP/Servlet will just kill it?

How should I call my business methods from JSP/Servlets?
Also, the system will have pretty a lot of users, so I need to be sure that nothing will be corrupted/crashed because of the implementation of this task.

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator

What is the easiest and proper way to make sure, that after invoking such business method our JSP/Servlet will wait for N seconds, and if method will not finish it's execution, so JSP/Servlet will just kill it?

Servlets and JSPs don't time out and writing something to make them do so, would be tricky at best.
What I do for long running processes is kick off the process and then immediately return the user to a status page that refreshes every n seconds. When the page refreshes it checks a status field. Once the status field is 'COMPLETE' I then redirect or forward the user to the content generated by the process.



How should I call my business methods from JSP/Servlets?
Also, the system will have pretty a lot of users, so I need to be sure that nothing will be corrupted/crashed because of the implementation of this task.
Thanks.

Assuming your JSPs, Servlets, and external processes are thread-safe, it just comes down to load testing and profiling to insure that your product is sufficiently scalable for it's intended purpose. A subject that is way beyond the scope of a forum post.

Let us know if you're not sure about thread-safety in a servlet app.
 
Olexiy Prokhorenko
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thank you for your response.

May be I wasn't clear in my question. I'll try to clarify below.

For example, my JSP looks like



and MyLib class has method helloWorld() which returns String.
This method executes method in some EJBs, which is doing many-many things, and that takes time. At the end, helloWorld() gets some return from EJB's method, mix it with something else, and creates String and returns it.
So, JSP successfully output it.

My goal is to do the following.
From class MyLib, from it's method helloWorld() I need to execute EJB's method. But If it will not finish it's work in 3 seconds (just for example!) - I still wish that method helloWorld() will return String "Sorry, EJB method failure!".

This way, in any case, JSP in max 3 seconds will do some output.
This is exactly what I need.



Thank you for your help.
[ February 13, 2005: Message edited by: Olexiy Prokhorenko ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
I understood the first question.
My answer is that I don't think what you're trying to do is a good idea.

What if the process succeeds but after 3.5 seconds?
 
Olexiy Prokhorenko
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Report post to moderator
I understand all possible limitations and minuses of such solution.
But in our application it's okay to follow them.

As a matter a fact, we can forecast that method will finish it's processing in 3 seconds (for example). This way, we will force MyLib to "kill" any non-finished method in 6 sec.
But we will know for sure that we will get response max. in 6 seconds.

This is what for I need such functionality.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hmm. The pattern I suggested can handle that.
I, personally, don't know of a clean way to impose a time limit on a request.

Maybe someone else does.
Good-Luck
-Ben
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
I was about to move this to the threads forum, but I see you cross-posted there already.

Please don't do that, it creates duplicate conversations and wastes the time of the people trying to help you, like you just did to Ben. This thread is closed.
 
    Bookmark Topic Watch Topic
  • New Topic