From: Lloyd Zusman Date: 2006-06-08T06:35:33+09:00 Subject: Re: how do I impose a method call delay? Jason Sallis writes: > My apologies, Lloyd...after re-reading my initial post, the language was > a little vague. Chris actually did get it right. I need the class to > be useable by a number of other classes, but each individual instance of > the class should impose its own delay. Although, after reading your > solution, it may be better to implement it your way in the future (time > permitting). I was looking at it as if each consuming application was a > "client" and each "client" should have the delay imposed, but I may want > to rewrite my class and think of IT as the "client" and impose the delay > globally for all consuming apps. Something to think about for me... Well, thanks for clearing that up. However, Chris's procedure, as written (i.e., without threading), will also not give you the results you are hoping for. The following is a sample chronology (note that each user has his/her own instance of last_get): 10:00:00 - User A invokes getDoc. User A's last_get is set to 10:00:00 and getDoc returns. 10:00:01 - User B invokes getDoc. User B's last_get is set to 10:00:01 and getDoc returns. 10:00:02 - User C invokes getDoc. User C's last_get is set to 10:00:02 and getDoc returns. 10:00:10 - User A calls getDoc. the process sleeps until 10:00:30 and then getDoc returns after setting User A's last_get to 10:00:30. *** NOTE: Without threading, the entire app will be hung in the 'sleep' call within this getDoc method. Users B or C cannot do anything, because they are all part of the same non-threaded app. 10:00:30 - User B invokes getDoc. It cannot make this call any earlier, because the entire app is sleeping during the call above. The process sleeps until 10:00:31 (because the last call that User B made was at 10:00:01), and then it returns after setting User B's last_get to 10:00:31 *** NOTE: Again, the entire app is waiting on the 'sleep' call, and users A and C cannot do anything. 10:00:31 - User C invokes getDoc. It cannot make this call any earlier, because the entire app is sleeping during the calls above. The process sleeps until 10:00:32 (because the last call that User C made was at 10:00:02), and then it returns after setting User C's last_get to 10:00:32 *** NOTE: Again, the entire app is waiting on the 'sleep' call, and users A and B cannot do anything. Notice that three URI access were made within three seconds, one group of three between 10:00:00 and 10:00:02, and the next group of three between 10:00:30 and 10:00:32. If you had 10 users, you could have as many as 10 requests, one right after the other at around 10:00:00, and then 10 more requests, one right after the other at around 10:00:30. This works out to 10 requests every 30 seconds. If you give each user its own thread, then you will get a chronology closer to what you want. However, with multiple threads, it's easily possible for requests to go to the web server at a much faster rate than once every 30 seconds. For example, for 10 users each having their own thread, this methodology results in web server get up to one hit every 3 seconds. Maybe this is OK. But if not, you'll have to rethink this approach. -- Lloyd Zusman ljz@asfast.com God bless you.