Re: MultiThreadModel-Problem?
hi, thank you all for your help hints, i'll check it out. Special thanks to Antony for his tip concerning ConcurrentHashMap-Implementation from Doug Lea! Bo, unfortunately i haven't the book Java Platform Performance, maybe you could give a summary from page 126? thank you all again! basti
MultiThreadModel-Problem?
hi, i use a servlet in MultiThreadModel-mode (default). when 2 users at the same time makes the same request to the servlet (a operation that needs a bit) it seams, that only the request of the user who was perhaps a millisecond earlier is responded correct, the other seams to be ignored. (i think, this is perhaps a concurency-problem, but i do not use static variables and could not find an error) the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti
Re: MultiThreadModel-Problem?
HttpServlet is not thread safe. Synchronize your code where needed - Original Message - From: Sebastian Schulz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 14, 2001 11:08 AM Subject: MultiThreadModel-Problem? hi, i use a servlet in MultiThreadModel-mode (default). when 2 users at the same time makes the same request to the servlet (a operation that needs a bit) it seams, that only the request of the user who was perhaps a millisecond earlier is responded correct, the other seams to be ignored. (i think, this is perhaps a concurency-problem, but i do not use static variables and could not find an error) the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti
RE: MultiThreadModel-Problem?
It isn't just 'static' variables that you have to be careful of, normal instance variables should be avoided too. You see, one instance of a servlet may service many many people (often there is only ever one instance of a particular servlet!). If you are sharing any data structure between threads, then you have to protect them with synchronized blocks. That means that you could use HashMap, even if it is being shared but you will have to make sure that only one thread ever tries to access it at any time.. -ie by gaining a lock on the HashMap itself. I hope that helps, but with out seeing code I cann't be much more exact. - Chris. Brainbench MVP Java2. -Original Message- From: Sebastian Schulz [mailto:[EMAIL PROTECTED]] Sent: 14 June 2001 16:09 To: [EMAIL PROTECTED] Subject: MultiThreadModel-Problem? hi, i use a servlet in MultiThreadModel-mode (default). when 2 users at the same time makes the same request to the servlet (a operation that needs a bit) it seams, that only the request of the user who was perhaps a millisecond earlier is responded correct, the other seams to be ignored. (i think, this is perhaps a concurency-problem, but i do not use static variables and could not find an error) the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti -- NOTICE: The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect), so that the sender's address records can be corrected.
RE: MultiThreadModel-Problem?
I'm new to all this, but is this (HttpServlet not being thread safe) a Tomcat problem, or just a general JSP problem, which will show up no matter what server I use (weblogic, for instance)? -Original Message- From: Luba Powell [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 14, 2001 8:20 AM To: [EMAIL PROTECTED] Subject: Re: MultiThreadModel-Problem? HttpServlet is not thread safe. Synchronize your code where needed - Original Message - From: Sebastian Schulz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 14, 2001 11:08 AM Subject: MultiThreadModel-Problem? hi, i use a servlet in MultiThreadModel-mode (default). when 2 users at the same time makes the same request to the servlet (a operation that needs a bit) it seams, that only the request of the user who was perhaps a millisecond earlier is responded correct, the other seams to be ignored. (i think, this is perhaps a concurency-problem, but i do not use static variables and could not find an error) the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti
Re: MultiThreadModel-Problem?
No, nothing like that. It is a feature of JVM (and most operating systems). Class and instance variables can be accessed by other thread in the same JVM. Only local variables are not exposed. There are numerous ways to protect the integrity of class and instance data. However, if you are new to the multi-threaded environment you might want to use a single threaded servlet model first. Since this is not a tomcat question - please write to me directly and I can explain you further the cons and pros of each model. R/Luba - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 14, 2001 12:50 PM Subject: RE: MultiThreadModel-Problem? I'm new to all this, but is this (HttpServlet not being thread safe) a Tomcat problem, or just a general JSP problem, which will show up no matter what server I use (weblogic, for instance)? -Original Message- From: Luba Powell [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 14, 2001 8:20 AM To: [EMAIL PROTECTED] Subject: Re: MultiThreadModel-Problem? HttpServlet is not thread safe. Synchronize your code where needed - Original Message - From: Sebastian Schulz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 14, 2001 11:08 AM Subject: MultiThreadModel-Problem? hi, i use a servlet in MultiThreadModel-mode (default). when 2 users at the same time makes the same request to the servlet (a operation that needs a bit) it seams, that only the request of the user who was perhaps a millisecond earlier is responded correct, the other seams to be ignored. (i think, this is perhaps a concurency-problem, but i do not use static variables and could not find an error) the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti
Re: MultiThreadModel-Problem?
OK to use, but only in certain context: protected Map clientList = Collections.synchronizedMap( new HashMap()); Notice the reference to the static method... - Original Message - From: Bo Xu [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 14, 2001 1:11 PM Subject: Re: MultiThreadModel-Problem? Sebastian Schulz wrote: [...] the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti Hi :-) in a book: Java Platform Performance ISBN: 0-201-70969-4, in about Page 126, there are disscussion and benchmark about the following: - Vector - (mutable) Java 2 Collections - immutable(unmodifiable) collection wrappers BTW, java.util.Collections also has synchronized wrapper Bo June 14, 2001
Re: MultiThreadModel-Problem?
Sebastian Schulz wrote: [...] the second question is: data-container like HashMap or HashSet are considered to be not Thread-save. Can i use such containers in a MultiThreadModel-Servlet or must i use only slower structures like Vector? your help is realy needed, many thanks in advance! basti Came across a very useful class developed by Doug Lea, author of Concurrent programming in Java in version 1.3.0 of his concurrent package. This package contains ConcurrentHashMap which provides concurrent reads, writes and iterations (including removal during iteration) over the Map. See the package pages http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html Doug says that a class of this sort is likely to be included in JDK1.5 and is looking for feedback on good/bad experiences with the new class. Antony