Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 959143

Pages: 1 | 2 | (show all)
Anonymous
Unregistered




Re: Write thread-safe servlets [Re: Anonymous]
      #16772 - 04/01/05 01:39 AM

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.)


Post Extras: Print Post   Remind Me!   Notify Moderator  
pankajgaur
Unregistered




Re: Write thread-safe servlets [Re: Anonymous]
      #35197 - 08/10/06 04:33 AM

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.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Anonymous
Unregistered




Re: Write thread-safe servlets [Re: Anonymous]
      #35250 - 08/11/06 03:46 AM

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
}


Post Extras: Print Post   Remind Me!   Notify Moderator  
Anonymous
Unregistered




Re: Write thread-safe servlets [Re: JavaWorld]
      #35642 - 08/22/06 12:08 PM

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


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1 | 2 | (show all)



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 25306

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5