• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton class

 
Roel De Nijs
Sheriff
Posts: 10203
129
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a class that's reading a file and it has to happen once, so i made a singleton. I have 2 web-apps, both using same file. Now the file is read twice (one time with webappA and once with webappB)

So i am looking to create a singleton on server-level instead of application-level

Anyone knows how to do this or is it mission impossible?
 
asirob civokviz
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is possible but problem is that you run two different applications and
every in it's own JVM instance!!! So classical singleto pattern wouldnot
work. You should try to find some pattern which is "network aware". Think
I saw some article on this a month ago at http://www.theserverside.com

search
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be managed in Concurrent User to write file.


Concurrent Programming with java
http://www.mcs.drexel.edu/~shartley/ConcProgJava/

Concurrent Pattern
http://www.cs.wustl.edu/~schmidt/patterns-ace.html
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is possible but problem is that you run two different applications and every in it's own JVM instance!!!

No - there is only one JVM per Tomcat server. Perhaps you meant each has its own class loader. See the tomcat class loader how-to installed in tomcat-docs with a typical tomcat installation.
Bill
 
asirob civokviz
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry,
just saw what I said... My mistake
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic