Store some data when JVM is active

Discussion in 'Java' started by tomas, Oct 19, 2007.

  1. tomas

    tomas Guest

    It is possible to store some data (very samall amount) when JVM is
    active (disable) in pc ? It is situation.. I run one java application
    (Swing app) few minutes leater run another application (also Swing
    app) and for example applet on this same pc this same JVM and I must
    store some data which the firsrt and second app (Swing) and applet can
    read... I can`t use any database, file itc... So a looking for some
    solution witch score data in JVM environment... It is possible ?
    tomas, Oct 19, 2007
    #1
    1. Advertising

  2. tomas

    Alessio Guest

    Not sure I understand exactly what you want... but, have you
    considered using static fields ("class variables")? They're allocated
    when the owning class is loaded and remain accessible for the entire
    lifespan of the JVM. So different applications running inside the same
    VM can access them. Of course you'll need to build an abstraction upon
    such field(s), so that you can e.g. handle concurrency in a
    transparent way, and in general adopt the good practice of denying
    direct access to the fields, masking it with method calls.
    Of course this works only if you are certain that all your apps will
    run inside the same VM. If the VM is shut down, or the system crashes,
    etc., any non-persistent state is of course lost.
    Just my 2 cents...

    cheers
    Alessio S.
    Alessio, Oct 19, 2007
    #2
    1. Advertising

  3. tomas

    Lew Guest

    Alessio wrote:
    > Not sure I understand exactly what you want... but, have you
    > considered using static fields ("class variables")? They're allocated
    > when the owning class is loaded and remain accessible for the entire
    > lifespan of the JVM. So different applications running inside the same
    > VM can access them. Of course you'll need to build an abstraction upon
    > such field(s), so that you can e.g. handle concurrency in a
    > transparent way, and in general adopt the good practice of denying
    > direct access to the fields, masking it with method calls.
    > Of course this works only if you are certain that all your apps will
    > run inside the same VM. If the VM is shut down, or the system crashes,
    > etc., any non-persistent state is of course lost.
    > Just my 2 cents...


    Static variables are dangerous, albeit sometimes useful. Some folks advocate
    never exposing a static variable (except for compile-time constants and
    immutable fields).

    OP: Running "one application" then "another application" implies two JVMs,
    despite the phrase "same JVM". How are you loading the second app?

    You also use the term "applet", which in the Java universe means something
    very, very different from "application". Which is it?

    --
    Lew
    Lew, Oct 19, 2007
    #3
  4. tomas wrote:
    >It is possible to store some data (very samall amount) when JVM is
    >active (disable) in pc ? It is situation.. I run one java application
    >(Swing app) few minutes leater run another application (also Swing
    >app) and for example applet on this same pc this same JVM and I must
    >store some data which the firsrt and second app (Swing) and applet


    Applets are run within a strict security sandbox unless
    the code is digitally signed, and accepted by the user.
    Even then, the paths that they can right/read form, might
    be very limited (e.g. latest IE/Vista bug).

    Do your end users really need an applet?

    Applets can be launched using Java Web Start*, but
    if you want something free floating, you might as
    well use a (J)Frame.

    JWS apps. also get a security sandbox, but the JNLP API
    allows us to 'break out' of it (with user permission), to do
    things like access files**.

    Even better, JWS provides the 'muffin' (like a cookie, but
    for web start) that allows us to share information across
    different apps. from the same codebase ('site'). This is
    in the PersistenceService***.

    * <http://www.physci.org/jws/#jtest>
    ** <http://www.physci.org/jws/#fs>
    *** <http://www.physci.org/jws/#ps>
    (but perhaps Sun has a better example of sharing
    the muffins *between* apps)
    <http://java.sun.com/j2se/1.4.2/docs/guide/jws/developersguide/examples.html#PersistenceService
    >


    >..can
    >read... I can`t use any database, file itc... So a looking for some
    >solution witch score data in JVM environment...


    Don't store any information within the JRE
    directories themselves.

    >...It is possible ?


    Sure - web start is one way.

    There are other ways for 'full permission' standard
    desktop apps (Properties, Preferences..).

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
    Andrew Thompson, Oct 19, 2007
    #4
  5. Andrew Thompson wrote:
    ...
    >Applets are run within a strict security sandbox unless
    >the code is digitally signed, and accepted by the user.
    >Even then, the paths that they can right/read form, ...


    'write/read from' (oops!)

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via http://www.javakb.com
    Andrew Thompson, Oct 19, 2007
    #5
  6. Lew wrote:
    ..
    >OP: Running "one application" then "another application" implies two JVMs,
    >despite the phrase "same JVM". How are you loading the second app?


    My entire answer was based on the assumption that the JVM
    might be 'completely shut down' between running one app. and
    the other.

    I think this really comes down to 'storing state between runs'
    (but in this case - sharing data across different apps. as well).

    >You also use the term "applet", which in the Java universe means something
    >very, very different from "application". Which is it?


    I am hoping the OP mentioned applet simply to stress that
    these were entirely different apps, running in (one might
    expect) different VMs. For that reason, I do not think
    'static' will work for the problem (as I vaguely understand
    it).

    I might be completely wrong. I did have trouble
    understanding exactly what the OP meant.

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via http://www.javakb.com
    Andrew Thompson, Oct 19, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    617
    =?Utf-8?B?UnVkeQ==?=
    Mar 30, 2005
  2. Kevin Hooke

    Re: Handling both MS JVM and Sun JVM

    Kevin Hooke, Aug 26, 2003, in forum: Java
    Replies:
    2
    Views:
    862
  3. Lasse
    Replies:
    1
    Views:
    680
    Jon A. Cruz
    Jan 5, 2004
  4. Young-Jin Lee

    MS JVM and Sun JVM problem

    Young-Jin Lee, Jan 20, 2004, in forum: Java
    Replies:
    3
    Views:
    562
    Mickey Segal
    Jan 21, 2004
  5. Jack
    Replies:
    2
    Views:
    339
    =?ISO-8859-2?Q?Dra=BEen_Gemi=E6?=
    Jun 17, 2006
Loading...

Share This Page