Store some data when JVM is active

T

tomas

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 ?
 
A

Alessio

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.
 
L

Lew

Alessio said:
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?
 
A

Andrew Thompson

tomas said:
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
 
A

Andrew Thompson

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!)
 
A

Andrew Thompson

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top