instance needs to be final, or it may be changed by some tricks that
break encapsulation.
On Sat, 2005-08-06 at 15:59 -0400, Mauricio Nuñez wrote:
> Improved version without sync locking:
>
> class SingletonObj
> {
>
> private static SingletonObj instance;
>
> static
> {
>
Improved version without sync locking:
class SingletonObj
{
private static SingletonObj instance;
static
{
instance=new SingletonObj();
}
private SingletonObj()
{
}
public static SingletonObj getInstance() // wit
{
private static final SingletonObj singleton;
// optional - use if you want the initialization to occur as class load
time
// Otherwise, the initialization will occur at first call to
getSingleton();
// static initialization at load time
static {
getSingelton ()/
}
private SingletonObj ()
private static final SingletonObj singleton;
public SingletonObj ()
{
super ();
singleton = this;
}
public synchronized SingletonObj getSingleton ()
{
if ( singleton == null )
{
new SingletonObj();
}
return singleton;
}
On Fri, 2005-08-05 at 20:11 -0700, Ming Han wrote:
> You can
You can use Singleton pattern, but care must be taken.
For example
if ( singleton == null )
{
singleton = new SingletonObj();
}
There might be a case where few thread running concurrently on the null
checking, then multiple singleton object will be created more than one.
__
You can also use the Singleton pattern, so no matter what happens,
you'll only have a single instance of your object.
- Behi
On 8/5/05, Jon Wingfield <[EMAIL PROTECTED]> wrote:
> Use a ServletContextListener, they were added to the Servlet 2.3 spec
> for this very purpose.
> You set up your objec
Use a ServletContextListener, they were added to the Servlet 2.3 spec
for this very purpose.
You set up your object in the contextInitialized(...) method of your
implementation and tear it down in contextDestroyed(...). For it to be
used you need to add it to your web.xml.
The container is fre
Hi,
You could have two instances of your object because of an improper
mapping in web.xml. For example if in your servlet mapping the
url-pattern for your servlet is /*, any access to your app will access
this servlet thus resulting in two instantiations.
You should initialize your object in the
Darren Govoni wrote:
How can I have my servlet loaded on startup, but
after the web server is up and running? Not possible?
Well, you can always start a thread that does this initialization, and
return. Then, when the full Tomcat initialization is complete, your
thread will run to completion (ass
Darn it. Thanks anyway.
Well, I think it makes a lot of sense to delay loading some servlets
until AFTER the server is up and running. Maybe soon we will see such an
operation.
maybe?
-100
On Sun, 2005-03-06 at 10:00 -0500, Tim Funk wrote:
> If you are performing a http request during init()
If you are performing a http request during init() - you are out of luck.
If you need to load resources (plain old files) - you can use
ServletContext.getResourceAsStream()
-Tim
Darren Govoni wrote:
Hi,
I wasn't able to do a full text search of archive message bodies on
this, so pardons if its
Great ideas Yoav. Thank you for your comments/input.
--JW
Shapira, Yoav wrote:
Hi,
Hmm, then is there a recommended way for managing child threads that
are
kicked off by a servlet? My servlet reads an XML file to determine what
classes to create and run - but if the Servlet itself goes a
Hi,
>Hmm, then is there a recommended way for managing child threads that
are
>kicked off by a servlet? My servlet reads an XML file to determine what
>classes to create and run - but if the Servlet itself goes away and
then
>is re-init()ed it will attempt to start those classes again. Does every
Hi,
Shapira, Yoav wrote:
Hi,
servlet). These are daemon threads, and have the setDaemon(true) set
for
the thread before I kickoff the runnable class. The problem I'm
experiencing is that when the context needs to be reloaded these child
threads are not killed, but continue to run.
W
Hi,
>servlet). These are daemon threads, and have the setDaemon(true) set
for
>the thread before I kickoff the runnable class. The problem I'm
>experiencing is that when the context needs to be reloaded these child
>threads are not killed, but continue to run.
Why would they be killed? The JVM
I'm working on getting the next release out on TC5. I don't think that
would fix my threading issue, however.
JW
Ben Souther wrote:
If upgrading Tomcat is possible, a context listener would be a better
design.
On Mon, 2004-10-18 at 15:51, Jonathan Wilson wrote:
I have a 1 Servlet on TC3.3.1(u
If upgrading Tomcat is possible, a context listener would be a better
design.
On Mon, 2004-10-18 at 15:51, Jonathan Wilson wrote:
> I have a 1 Servlet on TC3.3.1(under
> RH7.3) which checks an XML file which contains a list of Runnable
> classes to kick off at servlet startup. These child thr
Steffen,
As soon as I start using 2 coyote connectors together with
tomcat initializes the database pools twice.
Interestingly it keeps initializing things twice even if I add a third
coyote.
In about two minutes, Yoav Shapira is going to tell you this:
"Don't use a servlet to initialize your st
Howdy,
>As soon as I start using 2 coyote connectors together with startup>
>tomcat initializes the database pools twice.
>Interestingly it keeps initializing things twice even if I add a third
>coyote.
You have one load-on-startup tag for each servlet element in web.xml,
and one servlet element
Title: RE: load-on-startup order
So load-on-startup only orders within an application, not between applications?
Application A is a message handler. Application B is a listener which must register with A when it starts, so A can forward incoming messages to B. Therefore, B can't lazy
Instead of performing the necessary logic in the init method, why not try
"lazy-loading." Only initialize whatever you need when it is requested the
first time. By the way, what are you trying to do? I've never heard of
anyone having this kind of requirement/architecture. Just curious.
- O
Mayne, Peter wrote:
Tomcat 4.1.18
I have two applications, A and B, where a servlet in B depends on a servlet
in A being up, so I have
in A's web.xml:
...
1
in B's web.xml:
...
5
which should make A start first. However, when Tomcat starts, B's init() is
called first.
Jeff,
Try 10 and 20 or 1 and 2.
I know negative numbers don't necessarily start up before 1, maybe 0 doesn't
either.
Andy
> -Original Message-
> From: Jeff Wishnie [mailto:[EMAIL PROTECTED]]
> Sent: 05 September 2002 18:22
> To: Tomcat Users List
> Subject: load-on-startup order seems
"PELOQUIN,JEFFREY (Non-HP-Boise,ex1)" wrote:
>
> However, I have noticed that if I restart the context using the manager, the
> servlet are initialized according to their physical order in web.xml, thus
> ignoring the load-on-startup tag.
>
You might want to just go ahead and report it as a bu
Perhaps the problem is that your servlet *is*
being started, but is throwing an exception
during constructor or init method..print
statements in your constructor and init method
should prove this one way or another.
The load-on-startup value is just an integer that
indicates order of startup (low
25 matches
Mail list logo