• Post Reply Bookmark Topic Watch Topic
  • New Topic

Design approach  RSS feed

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a java file "DatabaseConnection.java" and DatabaseConnection object is singleton.I want to use make the DatabaseConnection singleton to run on a server.I have no clue as to how to do this.I want use J2ee Utility features while I am doing this.
Any help would be appreciated.
thanks
nash
 
Bartender
Posts: 9444
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean make a client-server application or a web service? There's several different architectures for accomplishing such a task. There's RMI, which is probably the simplest way to get client-server to work. You could develop your own protocol and do Custom Networking with sockets. The J2EE Tutorial covers the web technologies like SOAP, web services, servlets and so on. Each of these approaches has their own strengths and weaknesses and it is pretty much dependent on your application's requirements which one you should use.
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're asking to have a singleton object on the server. A safe pattern form making a singleton is:

Now with that said, a single instance of a database connection sounds like a bottleneck. A server generally has multiple threads handling requests for multiple clients at the same time. You'll have to do something to synchronize access so you don't have multiple threads using the database connection at the same time. That means if two (or 1000) requests come in quickly, each will have to wait its turn to use the connection. That could be very slow.
Look around for information on connection pooling. This is a feature of many database drivers and/or the latest EJB containers.
 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks people,as stated I would like to make a J2EE utility out of it,so that it is the current tred no a days.
Kindly guide me through, cause it would be really very helpful.

Thanks
NasH
 
Joe Ess
Bartender
Posts: 9444
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nash avin:
Thanks people,as stated I would like to make a J2EE utility out of it,so that it is the current tred no a days.

And as I stated, J2EE encompasses many technologies. If all you have is a connection pool using EJB's is silly because most EJB containers incorporate a connection pool. Deciding between SOAP, XML web services, Servlets and so on depends on what kind of information you are serving and what your audiance is. Perhaps you should start by going through the J2EE tutorial and gaining some knowledge about the different options available.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!