Anonymous
Unregistered
|
|
Agreed. Too basic is relative. I've been fighting with thread-safety in an application I'm developing. This article explained things in a clearer fashion than I've seen in the other articles/books I've read.
I will admit, I'm still feeling uneasy about the subject as a whole, because I'm trying to understand Java Beans and JSP at the same time. It seems like Bean classes are supposed to use instance variables, and the JSP getProperty action retrieves the values of those instance variables. There is also a disconnect between the time you set the variables in your servlet and the time the page executes the getProperty action, which has caused me to pull every single hair I have out of my head!
Nevertheless, I presume that if I continue to go back to the basics, concentrate harder, and read progressively more complex articles, I'll eventually get it. (Truth be told, I'm not happy that I as an application developer have to worry about this. Mainframe application programmers have never had to worry about thread safety. It should be taken care of by the O/S and/or servlet container, as far as I'm concerned.) 
|
pankajgaur
Unregistered
|
|
i tried with a normal class but it didnt worked the way u explained i.e "sync(this) = sync void method" it didnt sync the entire method, it just did the block much like a syn(mutex) had performed. i am not sure this has to do with servlet / normal class issue.
|
Anonymous
Unregistered
|
|
hi i am not sure i understand your point well. you mentioned syn (this) is equal to syn on method itself like ---------------------------------
void method() { syn(this){ // some code here } ++is equal to ++ syn method() { // same code here } ---------------------------------------------- but my point is it should be equal only if u hv nothing else in the method that remains unsyn. i.e ------------------------------------------------------ void method(){ // code A syn(this) { // code B } } ++is not equal to ++ syn void method(){ // code A // code B }
|
Anonymous
Unregistered
|
|
Hi everyone,
I used the code presented in this article and i don't get the result you presented. I understand my tomcat server isn't making multiple threads when multiple requests are made.
I get this result:
testthread.TestServlet@4bfe6b: Counter = 160 Counter = 161 Counter = 162 Counter = 163 Counter = 164 Counter = 165 Counter = 166 Counter = 167 Counter = 168 Counter = 169
testthread.TestServlet@4bfe6b: Counter = 170 Counter = 171 Counter = 172 Counter = 173 Counter = 174 Counter = 175 Counter = 176 Counter = 177 Counter = 178 Counter = 179
etc.
Is my Tomcat configuration wrong or have i made another mistake? It looks like my servlet implements the SingleThreadModel interfac, but it doesnt.
Can anyone help me with this?
Jan
|