• 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

static instance doesn't work

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have an static instance that works when i run once.
but when i try to run to them in diffrent shell.this term get always evaluated.


i cant understand why

is executed more than once if i run many program in same jvm?
help please !!!

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every time you run "java.exe" (or the equivalent on other platforms) from the command line, you are actually creating a new JVM, running a completely separate programs. Static variables are not shared across JVMs, only within a single JVM -- i.e., within a single java.exe.

If you want one JVM to include multiple independent "programs" running at the same time, consider using threads. You could invoke your code in multiple threads, and all of them would run at once.

If you want multiple JVMs to share the same variables, you have to set that up explicitly using some kind of networking technology (RMI, JavaSpaces, JINI, CORBA, etc.) This is never a trivial undertaking, nor is it ever completely transparent.
 
Moh Ghasemi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,
is there any way for sharing static variable across JVMs?
otherwise i think , i have to use RMI.

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is there any way for sharing static variable across JVMs?



No.

otherwise i think , i have to use RMI.



Well, you have to refactor your program to keep the JVMs static values in sync. And RMI could help with the network communications.

Henry
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic