File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Bypass Code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Bypass Code?" Watch "Bypass Code?" New topic
Author

Bypass Code?

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
I have a method call on one line and immediately afterwards I have a different method call. The first goes and reads a record in and assigns it to a variable and the other writes. In JSP is it possible for the second method to be hit before the first has finished? If so, how can I avoid this from happening? The method calls are third party. Thanks.

RH
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

No. JSPs are translated into servlets for execution on the server by a JVM. All the rules of Java apply. Which means that statements will be executed in sequence.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
Hi Bear,
The reason why I'm asking is that it appears the lock held by the read has not been released before the write method call directly after it. Have you encountered anything like this? I know you said sequential processing just wondering about a database lock sticking around long enough for the write to complain it's already locked. Is there a straight up way to sleep or nap for a small amount of time in JSP to test this theory out? Thanks again.

Rob
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

Not to be persnickety, but doing DB access in a JSP is an egregious violation of all best practices and patterns. And a pain in the rear to debug.

My advice is to factor all that code out of the JSP into a Java class that you can test stand-alone. A much easier scenario to debug.

Once you you've got things working there, you can either connect to this code via a bean in the page (poor, but better than code in the JSP), or in a servlet controller for the page (much better) all under Java control.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bypass Code?
 
Similar Threads
which method call first?
Rookie Question about Servlet's Service method
this() and super() calls
whats this mean
Thread