Antonio Mancuso wrote:
>
> Hello,
> I need to develope a servlet that manages a FIFO queue. In fact I need I
> think that the queue it will be a critical section, so I need to manage the
> synchronization
> of the servlet to access the queue.
> I think to use the SingleThreadModel.

Unless there is some other reason to use SingleThreadModel, using it to solve
your problem is not the best solution. SingleThreadModel does not mean that only
a single servlet instance runs, it means that only a single thread will run in a
class instance at any time. Unless you have some way to configure the servlet
engine to allow only a single servlet instance, you will have multiple servlet
instances handling concurrent requests. Thus, you would still need to manage
access to the queue.

A better solution would be to write your servlet class to be able to
concurrently handle multiple requests.

> I don't know what really happens in this case. for example:
> when the first servlet is launched it lock the queue; but if at the same
> time arrive another request for a servlet
> this one cannot access to the queue, and what happens?
> I lost the request?

The same thing that happens in any multi-threaded class: One thread will get to
the critical section and will lock the monitor for that method or block of code.
The second thread will start and when it reaches that same point in the code, it
will block until the first thread releases the monitor and the second thread can
obtain access to the monitor.

Multithreading issues have been discussed several times on this mailing list. If
you can access the archives, you should check for previous discussion of
threading issues. You can also check Sun's Java tutorial
(http://java.sun.com/docs/books/tutorial/index.html) for information on
multithreading. There are many more possible sources of information, so don't
limit yourself to just the two I listed.

Kevin Mukhar

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to