aspose file tools*
The moose likes Servlets and the fly likes Calling Java Servlet from another java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling Java Servlet from another java class" Watch "Calling Java Servlet from another java class" New topic
Author

Calling Java Servlet from another java class

Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 128
Hi,

I'm needing to call a java servlet from a seperate java class using a PL/SQL function for an application residing on Oracle Application Server. What steps should I keep in mind in order to make the code thread-safe? I understand that I should avoid instance variables. Also, make any variables whose values remain constant as 'final'. So far, I've only been able to call java methods from PL/SQL functions that are defined as 'public' & 'static'. I don't want to impliment the single-threaded model since this application will be fairly high volume.

Thanks in advance,

Mike
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
The only way to get information out of a servlet based web application is by creating a request and getting a response. Typically with a HttpURLConnection or a toolkit like HttpClient that manages a HttpURLConnection.
If you have to write the servlet, then yes, all the usual thread safety considerations apply.
This sounds sort of like a "Web Service" - is that what you have in mind?
Bill


Java Resources at www.wbrogden.com
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
I don't want to impliment the single-threaded model
The SingleThreadModel has been depreciated anyway. It turned out to be remarkable thread unsafe, especially when it came to sessions.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by Paul Bourdeaux:
The SingleThreadModel has been depreciated anyway. It turned out to be remarkable thread unsafe, especially when it came to sessions.


It used to be appreciated, but not anymore.

If this is a Web Service, wouldn't you call it using an HttpConnection. If it not a web service, I am assuming that the call would not be to doPost, etc... And if my assumption is correct, I highly recommend a refactor being done to remove the shared code from the Servlet into a Plain Old Java Object.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
A simple URL class in your application may be able to do the trick. Using URL class you can connect to server and get the page that the servlet sends out and process the page in your application.


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling Java Servlet from another java class
 
Similar Threads
convert to java stored proceedure for oracle
How to execute PL/SQL block within JSP ?
Calling servlets
Using JDBC for a remote call in Oracle
Execute pl/sql function which is having bind variables in java