You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Teja Palla <te...@synapse.ws> on 2007/08/09 16:01:50 UTC

Embedded or Network Framework?

I am new to Derby and unable to figure out which framework suits my situation: Embedded or NetworkServer framework.
I have a java application (which is a media server, sort of like flash media server, but written all in java), for which I wish to use derby as its database. The app will have say stuff like channels and channel schedules etc... very small database, just one database. Now, on the same machine in the java application I also embed (load) a servlet container (winstone: http://winstone.sourceforge.net/).

Later on, I develop web applications where say users can look at the available channels and schedules.. (so the web app needs database interaction).

So my question is, what framework needs to be used? will embedded framework suffice because I see only one JVM here? Please advise..

Re: Embedded or Network Framework?

Posted by "John H. Embretsen" <Jo...@Sun.COM>.
Teja wrote:
> Ah, you nailed it for me.. so the documentation changed the definition of JVM
> a bit.... Thanks a lot.

Well, I wouldn't go as far as to say that, but as long as you get the 
picture, that's great! Keep on coding :)


-- 
John



Re: Embedded or Network Framework?

Posted by Teja <te...@synapse.ws>.
Ah, you nailed it for me.. so the documentation changed the definition of JVM
a bit.... Thanks a lot.


John H. Embretsen-3 wrote:
> 
> Teja wrote:
>> Thanks Manjula, John and Bryan; Not very clear yet, but in my situation
>> of a
>> web server( strictly, application server) and a java app (actually a
>> media
>> server app.. serves flash video files basically and lots of other
>> functionality)
>> both on the same machine (and hence only one JVM in its normal
>> definition)
>> where java app loads the web server (web server is shutdown when java app
>> shuts down)
>> ,  so in this situation, I think embedded framework will suffice (as long
>> as
>> the java app 'load's the embedded driver before web server is loaded and
>> none of the web apps try to 'load' the derby embedded driver again.).
>> I think I should be able to simultaneously (from the java app and also
>> from
>> any http requests to the web apps) be able to access/modify same database
>> (will be booted by java app once after the driver is loaded)
>> without any fears of data corruption..
> 
> I think one important thing to be aware of here is what the 
> documentation means when it speaks of a JVM.
> 
> For example, even though you may have only one JDK or JRE installed on 
> your system, you will create a new JVM instance every time you use the 
> "java" command (the command could be something else, depending on JVM 
> vendor etc.). That is, you start a new Java Virtual Machine (JVM) every 
> time you invoke the Java launcher (e.g. "java").
> 
> The last part of the documentation paragraph you quoted in a previous 
> post describes a scenario where the user's Java application accesses the 
> database from one JVM instance (e.g. "java MyApp"). Then, if you try to 
> access the database from another JVM (instance), say the ij tool, you 
> may corrupt the database (but you will most likely be stopped (getting 
> an exception with a warning) before it goes that far).
> 
> In some environments with "complex" classloading this gets a bit more 
> fuzzy, as Bryan mentioned, since the built-in multi-boot prevention 
> mechanisms may be fooled.
> 
> However, having multiple concurrent connections to the same database 
> from the same JVM in a pure embedded framework, is safe.
> In any case you should back up your database regularly, in case 
> something happens.
> 
> Feel free to ask if you have more questions after your try-outs...
> 
> 
> -- 
> John
> 
> 
> 

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


Re: Embedded or Network Framework?

Posted by "John H. Embretsen" <Jo...@Sun.COM>.
Teja wrote:
> Thanks Manjula, John and Bryan; Not very clear yet, but in my situation of a
> web server( strictly, application server) and a java app (actually a media
> server app.. serves flash video files basically and lots of other
> functionality)
> both on the same machine (and hence only one JVM in its normal definition)
> where java app loads the web server (web server is shutdown when java app
> shuts down)
> ,  so in this situation, I think embedded framework will suffice (as long as
> the java app 'load's the embedded driver before web server is loaded and
> none of the web apps try to 'load' the derby embedded driver again.).
> I think I should be able to simultaneously (from the java app and also from
> any http requests to the web apps) be able to access/modify same database
> (will be booted by java app once after the driver is loaded)
> without any fears of data corruption..

I think one important thing to be aware of here is what the 
documentation means when it speaks of a JVM.

For example, even though you may have only one JDK or JRE installed on 
your system, you will create a new JVM instance every time you use the 
"java" command (the command could be something else, depending on JVM 
vendor etc.). That is, you start a new Java Virtual Machine (JVM) every 
time you invoke the Java launcher (e.g. "java").

The last part of the documentation paragraph you quoted in a previous 
post describes a scenario where the user's Java application accesses the 
database from one JVM instance (e.g. "java MyApp"). Then, if you try to 
access the database from another JVM (instance), say the ij tool, you 
may corrupt the database (but you will most likely be stopped (getting 
an exception with a warning) before it goes that far).

In some environments with "complex" classloading this gets a bit more 
fuzzy, as Bryan mentioned, since the built-in multi-boot prevention 
mechanisms may be fooled.

However, having multiple concurrent connections to the same database 
from the same JVM in a pure embedded framework, is safe.
In any case you should back up your database regularly, in case 
something happens.

Feel free to ask if you have more questions after your try-outs...


-- 
John


Re: Embedded or Network Framework?

Posted by Teja <te...@synapse.ws>.
Thanks Manjula, John and Bryan; Not very clear yet, but in my situation of a
web server( strictly, application server) and a java app (actually a media
server app.. serves flash video files basically and lots of other
functionality)
both on the same machine (and hence only one JVM in its normal definition)
where java app loads the web server (web server is shutdown when java app
shuts down)
,  so in this situation, I think embedded framework will suffice (as long as
the java app 'load's the embedded driver before web server is loaded and
none of the web apps try to 'load' the derby embedded driver again.).
I think I should be able to simultaneously (from the java app and also from
any http requests to the web apps) be able to access/modify same database
(will be booted by java app once after the driver is loaded)
without any fears of data corruption..

If I burn my hands, I will then go back to the network server framework...
will let you know..

Thanks u all for ur time..

Teja wrote:
> 
> I am new to Derby and unable to figure out which framework suits my
> situation: Embedded or NetworkServer framework.
> I have a java application (which is a media server, sort of like flash
> media server, but written all in java), for which I wish to use derby as
> its database. The app will have say stuff like channels and channel
> schedules etc... very small database, just one database. Now, on the same
> machine in the java application I also embed (load) a servlet container
> (winstone: http://winstone.sourceforge.net/).
> 
> Later on, I develop web applications where say users can look at the
> available channels and schedules.. (so the web app needs database
> interaction).
> 
> So my question is, what framework needs to be used? will embedded
> framework suffice because I see only one JVM here? Please advise..
> 

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


Re: Embedded or Network Framework?

Posted by Bryan Pendleton <bp...@amberpoint.com>.
> Please clarify..

This is a tricky problem to explain clearly; it involves drawing
deep and careful distinctions in the use of terms like "application".
Specifically, you have to understand the behavior of Java class
loaders in an application server environment.

In most situations, the current Derby mechanisms for preventing
accidental dual-boot of a database work very well, but in some
app server environments they can be fooled, and you can accidentally
have two copies of the Derby engine servicing the same database,
and then the software does not work properly.

For a deep and detailed explanation of what's going on, start here:
https://issues.apache.org/jira/browse/DERBY-700

Your questions are important and completely legitimate and you
should continue to ask them, and refine your understanding of
how the Derby software works. I'm confident that you will be able
to configure the software to work adequately for your environment,
once you fully understand how the software works, and the various
configuration choices at your disposal.

thanks,

bryan


Re: Embedded or Network Framework?

Posted by Teja <te...@synapse.ws>.
:) 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 <te...@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.


Re: Embedded or Network Framework?

Posted by John Embretsen <Jo...@Sun.COM>.
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 <te...@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




Re: Embedded or Network Framework?

Posted by Teja <te...@synapse.ws>.
Thanks for your reply... In your case, I see only a web server connecting to
the database, even if there are multiple web applications, they still go
through the web server right, so there is only one JVM and embedded database
will suffice???

But in my case, I have a web server and another application both accessing
the database. I was leaning towards the network server framework, but I
wanted to eliminate the embedded solution. 

Because eventually, the java app and the web server and derby db are going
to be packaged as one. So I don't want to bring network framework in to
picture unless it is absolutely necessary.

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(?).

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?

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?


Manjula Kutty wrote:
> 
> Hi Teja,
> 
> Based on your description , I think Network Server will be the best
> solution. I have a java/jsp application which uses Derby and then I'm
> using
> a webserver to get the tables/ and rows and I use the networkserver for
> that
> application and it works like a charm. Hope this helps you
> 
> Regards,
> Manjula
> 
> 
> On 8/9/07, Teja Palla <te...@synapse.ws> wrote:
>>
>>  I am new to Derby and unable to figure out which framework suits my
>> situation: Embedded or NetworkServer framework.
>> I have a java application (which is a media server, sort of like flash
>> media server, but written all in java), for which I wish to use derby as
>> its
>> database. The app will have say stuff like channels and channel schedules
>> etc... very small database, just one database. Now, on the same machine
>> in
>> the java application I also embed (load) a servlet container (winstone:
>> http://winstone.sourceforge.net/).
>>
>> Later on, I develop web applications where say users can look at the
>> available channels and schedules.. (so the web app needs database
>> interaction).
>>
>> So my question is, what framework needs to be used? will embedded
>> framework suffice because I see only one JVM here? Please advise..
>>
> 
> 
> 
> -- 
> Thanks,
> Manjula.
> 
> 

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


Re: Embedded or Network Framework?

Posted by Manjula Kutty <ma...@gmail.com>.
Hi Teja,

Based on your description , I think Network Server will be the best
solution. I have a java/jsp application which uses Derby and then I'm using
a webserver to get the tables/ and rows and I use the networkserver for that
application and it works like a charm. Hope this helps you

Regards,
Manjula


On 8/9/07, Teja Palla <te...@synapse.ws> wrote:
>
>  I am new to Derby and unable to figure out which framework suits my
> situation: Embedded or NetworkServer framework.
> I have a java application (which is a media server, sort of like flash
> media server, but written all in java), for which I wish to use derby as its
> database. The app will have say stuff like channels and channel schedules
> etc... very small database, just one database. Now, on the same machine in
> the java application I also embed (load) a servlet container (winstone:
> http://winstone.sourceforge.net/).
>
> Later on, I develop web applications where say users can look at the
> available channels and schedules.. (so the web app needs database
> interaction).
>
> So my question is, what framework needs to be used? will embedded
> framework suffice because I see only one JVM here? Please advise..
>



-- 
Thanks,
Manjula.