db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Teja <t...@synapse.ws>
Subject Re: Embedded or Network Framework?
Date Thu, 09 Aug 2007 15:34:51 GMT

:) The reason I started asking q's instead of trying out stuff is because
derby documentation shookup my definition of JVM sort of.. I have been out
of java for a long time and only recently coming back, so wasn't sure if my
basics are right.. 

If in my development scenario (one java app, a servlet
container-and-webapps-it-serves, both accessing a derby database), now it is
clear that there is only one JVM.

I am thrown off by this paragraph in derby documentation (derbydev.pdf -
p.12)

"One Derby instance for each Java Virtual Machine
You could potentially have two instances of a Derby system (JVM) running on
the same
machine at the same time. Each instance must run in a different JVM. Two
separate
instances of Derby must not access the same database.
For example, in an embedded environment, an application that accesses Derby
databases starts up the local JDBC driver, which starts up an instance of
Derby. If you
start another application, such as ij, and connect to the same database,
severe database
corruption can result. See Double-booting system behavior."

Especially the last four lines.. it seems to indicate that on a machine, if
a java app loads the derby and another connects to it, corruption occurs.
But what they described, is it not almost same as my scenario? Is it not two
apps on a single JVM scenario? In such case why should a corruption occur?
Forget about ij for a moment ( I havent' totally pored on it yet), but say I
have app1 and app2 on the same machine, app1 'loads' the embeded driver (
and say runs forever), app2 doesn't 'load' the embedded driver, but tries to
use the same database as app1 is using. In such case, how many JVMs are
there? ( same machine, java installed only once, so afaik, only one JVM). Is
this the corruption scenario that the above paragraph is talking about? 
Please clarify..



John H. Embretsen-3 wrote:
> 
> Teja wrote:
> 
>> Can someone confirm this:
>> 
>> In my java app, on startup or so, I 'load' the embedded derby driver, so
>> the
>> database is ready to be used by the java app. But I also launch the web
>> server (separate thread) through the same app, so the web server is still
>> running in the same JVM(?).
> 
> Yes.
> 
>> And then there is a web app which accesses teh database (through the web
>> server ofcourse (?)).
>> So in my web app database classes, can I just ignore the 'load' driver
>> line.. Class.forName(..); and proceed directly with the embedded
>> connection
>> urls to access the db tables?
> 
> I would think so, unless there is some complex classloading trickery going
> on
> here... Why not just try and see ;)
> 
>> Note that at any given time, both the web app and java app will be
>> accessing
>> the same database. In such scenario, can someone confirm that there will
>> be
>> no data corruption and Embedded framework will take care of transactional
>> safety and such?
> 
> As long as the DB is accessed from the same JVM, you should be safe from
> this
> particular issue. If you are using a relatively new JVM and a relatively
> new
> Derby version, I think there are mechanisms in place to prevent you from
> booting
> the same DB in more than one JVM at once.
> 
>>> On 8/9/07, Teja Palla <teja@synapse.ws> wrote:
>>>> So my question is, what framework needs to be used? will embedded
>>>> framework suffice because I see only one JVM here? Please advise..
> 
> I think embedded will suffice. Also, with embedded you avoid the overhead
> of
> sending network traffic back and forth to the database server.
> 
> If, at a later stage, you find out that you need to connect to the
> database from
> multiple JVMs, you can always extend using an embedded server (see [1] for
> an
> explanation) instead, or a standalone server for that matter.
> 
> 
> -- 
> John
> 
> [1]:
> http://db.apache.org/derby/papers/DerbyTut/ns_intro.html#Embedded+Server
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Embedded-or-Network-Framework--tf4242840.html#a12074687
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Mime
View raw message