Basic questions about Tomcat

Hi all, I'm new to Tomcat and I have a few questions...

1) I have a HttpServlet class in my server. Will an instance of this class be created for each request?. For performance reasons, can I specify a number of instances to be pre-created before user requests? (creating them at user request may be too slow)

2) I'd like to know more about threads in Servlet Containers. If my HttoServlet class has an instance of a class, will the attributes of this class be thread-safe? How does this work?

thank you in advance

[541 byte] By [ciwee_ufrja] at [2007-11-27 9:20:04]
# 1

> 1) I have a HttpServlet class in my server. Will an

> instance of this class be created for each request?.

No. There is one instance of each servlet object.

> For performance reasons, can I specify a number of

> instances to be pre-created before user requests?

> (creating them at user request may be too slow)

On my laptop creating a simple object takes 0.00000001 seconds. Object creation is fast in Java; don't worry about it (unless you really are trying to create a hundred million objects per second and profiling shows that's the bottleneck in your application.)

> 2) I'd like to know more about threads in Servlet

> Containers. If my HttoServlet class has an instance

> of a class, will the attributes of this class be

> thread-safe? How does this work?

Don't put fields in servlets. Synchronize access to any data that are shared between threads.

sjasjaa at 2007-7-12 22:12:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...