• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

How does singleton work in client/server app?

Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a Java Swing application hosted on a server machine has a singleton, so when multiple clients access to that Swing app on that server, I assume each client's local machine will use its own JVM to run that app, correct? If that's the case, each local machine will create ONE singleton in its own JVM. So, that means there're a lot of singletons out there, and that defeat the purpose of using a singleton in the Swing app on the server trying to control how many instances to be created for a particular class, right?

So, my question is how to prevent that? Is it possible for multiple cients use the same singleton provided/created on the server JVM?
Posts: 17344
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the Swing App on the server side, how does the client's see the GUI, doesn't it only display on the Server. It is actually pretty easy to keep a Singleton on the Server. Just have the server pass back the one instance to all the clients, the instance stays on the server, you only have a Proxy object on the clients that make calls to the one object on the server.

I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
Enterprise-grade Excel API for Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!