• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can use Tomcat JNDI datasource from Standalone Java application

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beginner to J2EE, we have standalone java application which runs in Jaguar(SYBASE - EAServer) scheduler. As part of migrating all EAServer application into Tomcat, this particular scheduled standalone application using com.sybase.jaguar.jcm.JCMCache for accessing Database. currently i am planning to schedule this standalone in window's scheduler tasks and mapping with Tomcat JNDI datasource. Can someone guide me on this? I appreciate your help in advance..
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not clear on what you're attempting. If you are trying to convert the stand-alone app to run under Tomcat, there are significant architectural differences between webapps and stand-alone apps. Most notably, a webapp doesn't run as a thread, it runs as an on-demand responder to web requests.

The recommended way to access databases within a J2EE webapp is to use a JNDI datasource (connection pool), but the pool has to belong to the same JVM as the webapp. You define this pool as part of the Tomcat deployment description or server configuration and Tomcat's internal JNDI server is used to locate it. An external app's JNDI server isn't running under the same JVM.

If you are attempting to linke a web application to a stand-alone application and make use of the data persistence capabilities of that stand-alone application, your main problem is that the webapp and stand-alone app are going to be running under distinctly separate JVMs and therefore objects cannot be shared between them - pools, Connectors, even DTOs are limited to access from within the JVM that owns them. To transfer data between JVMs you need a serializing transport mechanism such as RMI or SOAP. Such mechanisms exist - EJBs were originally conceived as a data transfer and control mechanism using RMI, but that sort of stuff requires a lot of re-architecting on the behalf of the app that contains the data.

You could get around that by having your stand-alone app spin up an embedded Tomcat, but that opens an even larger can of worms and I don't recommend it unless you have a very clear idea of how things are going to interact and how to run an embedded Tomcat.
 
Vic Suyam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim for clear explanation. if i have to schedule this stand-alone thread app in windows scheduler outside of J2EE container means, what are the recommended ways we can access Database?
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you just want a stand-alone application without web interfacing, that's no problem, although this isn't the forum for details.

Basically, a stand-alone app can do anything it wants. You can write brute-force code to use JDBC, use an ORM such as JPA/Hibernate (done that many times), you can build the app on the Spring Framework, use OSGi to manage it, etc., etc., etc.

I did something several years ago that could run up to 8 hours. It processed about 3 million records against US Government watch lists and had to run daily. There were optimizations in it, but about once a week on average, a full run, lasting about 8 hours would kick in. At the time, the most appropriate technology for me was to do this as a stand-alone Java RMI application. The application was driven via RMI method calls from a web application. The web app also shared the database with this stand-alone app so that the users could review the results.

I'll be doing something similar again this week on a smaller scale. Since the batch run shouldn't exceed about 5 minutes, I'll probably employ recent improvements to JEE that support batch operations in webapps rather than write an external batch program. If it was expected to run longer, I'd outsource it to an external app, though, since I don't like my web applications "held hostage" to work in progress if we need to do an emergency update to the applications or something.
 
Vic Suyam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tim for your responses, I really appreciate it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic