is it possible to create single instance of java class per
session in web application
Answers were Sorted based on User's Feedback
Answer / savar33
Hi guys
the singleton solution will not work, since several nodes
are possible in the cluster, each node has it's own java.
Those singleton can be instanciated in each class.
Beside this the presented implementation of singleton design
pattern is improper. You should override constructor in this
way :
private Singleton(){};
I also would make getInstance() method synchronized. This is
multithreaded environment.
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / ananth
by using Singleton pattern we can achieve one instance per
class.
Public final class Singleton{
private static Singleton singleton;
public static Singleton getInstance()
{
if(singleton ==null)
{
singleton=new Singleton();
}
retuen singleton;
}
public void getvalue()
{
}
}
Is This Answer Correct ? | 7 Yes | 6 No |
Answer / nirmal
The easiest way is to use RMI to start the app and check to
see if it's already running.
The basic structure is this:
The main method of your app checks the RMI registry to see
if the app is started. If so, exit.
Otherwise, the main creates an instance of the app (which
is a remote object) and registers it in the RMI registry.
The class' constructor creates the GUI and displays it.
Alternatively, you could create a "start" method that you
call via RMI to start the app.
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / sk.bilal ahmed
yes
eg.,
Public final class Singleton{
private static Singleton singleton;
public static Singleton getInstance()
{
if(singleton ==null)
{
singleton=new Singleton();
}
retuen singleton;
}
public void getvalue()
{
}
}
Is This Answer Correct ? | 0 Yes | 2 No |
What is core java and j2ee?
What is layout in java?
Every field has setter and getter methods.what is happening in this methods.
What is distributed application?
what is the difference between Tomcat 4 & Tomcat 5?
What are the topics in j2ee?
How to achieve multiple inheretence in java.I need an example. how we achieve.
What is a jpanel in java?
There are 2 classes . Class A and Class B. In Class A i declared a variable in private. if we can access this private variable in Class B. If yes means , how we can access ?
7 Answers HCL, Itx Centrics, Virtusa,
Is class a data type in java?
explain the technologies that j2ee platform provides for developing components.
How to invoke stored procedure in hibernate?