What is ThreadSafe?

hiWhat is ThreadSafe. Servlets and JSP's are ThreadSafe or not . Give in detail.bye
[105 byte] By [sreedharm] at [2007-9-30 18:17:13]
# 1

Hi

In order to clarify some concepts :

Process : instance of an application running on a machine. Each process has a memory assigned (how depends on SO)

Thread : execution path. A process has almost one thread. Each execution path is scheduled by the SO. A process with many thread has a process memeory space shared by all these threads.

Thread save : code (executed by a Trhead) that not corrupts memory by accessing only local variables (at the scope of a thread) or accesing global variables with synchronization (only a thread at a time can acces

global variables etc).

So, servlets call service (and after doGet or doPost) run inside a thread so is mandatory that servlets be thrad safe.

A bad example: the sevlet object has a member java.sql.Connection and service uses these object in order to acces the database. This is not thread save because a thread can open connection

and other close it

Hope this helps

yomismo at 2007-7-6 19:26:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...