wood burning stoves 2.0*
The moose likes Servlets and the fly likes use diffrent servlet values (how to unload a servlet) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "use diffrent servlet values (how to unload a servlet)" Watch "use diffrent servlet values (how to unload a servlet)" New topic
Author

use diffrent servlet values (how to unload a servlet)

prashant patel
Ranch Hand

Joined: May 02, 2000
Posts: 69
I have This problem consider
1) a Servlet which redirects to specific class jsp page depending on the data acquired.
eg the an order no id-- 10. then data is gathered and analized on the order id and appropiately and redirected.
now this worked fine for one request at time. when two person
with order id = 40 and another with order id = 50 request the servlet but id of the second person is used. I tried with SingleThreadServlet model and synchronizing with "this" object and the "method" but no luck. how do i use diffrent data from diffrent request to the same servlet when the are request at the same point of time.
thank you.


prashz
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
How are you defining the variables that hold the id? If you're using static variables or perhaps member variables (class-scope) then there may be data collisions (though I doubt it in this case). Try a simple test where the id is declared within the doGet/doPost methods and simply log it to see if the problem persists. Something like this.

Hope this helps.
Sean
prashant patel
Ranch Hand

Joined: May 02, 2000
Posts: 69
thanks sean,
The Servlet get the order id from jsp, the problem comes
when: Multiple users use the same function at one moment at the same time using the same jsp and same servlet with diffrent order id, assume:
user (1) user id 00000001 and user (2) 00000002 (3) and simaliary 4,5,6,7. Now users get diffrents order ids coz the servlet users global data. the i put all the global data into the servlets doGet(), but stil get the same result, i put the entire doGet() code in the synchronize(this)scope, but get the same result. I is really dissapointing as the have declated functions in the servlet now i have to pass each data type as a
parameter to the function and then i end up with a long set of parameter list, then i realised i am coding C not java. I also used the Single Threaded Model but the same result. After the jsp page is loaded with diffrent id the data is submitted to
another servlet again the same result, with all the data again in the doGet(). Can you suggest and diffrent model or coding style or a diffrent technique in the threading, I my self am trying, I am questioning the java servlet it is disappointing.
i have to write everything in a single doGet() method.
thanks.
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Servlets are inherently multithreaded and (short of not using static variables) you generally do not even have to worry about theading or synchronization issues. You can have your controling logic within the doGet() method and make calls to non-static methods without concern. I think you should remove any threading/synchonizing code, create non-static methods as you need them and then build from there. I have a feeling, the problem is stemming from an area other than the servlet architecture itself. Look into designing the application to avoid the global (shared) data that you mention - this jumps out to me as the culprit. Don't get discouraged - the answer will reveal itself eventually
Sean
prashant patel
Ranch Hand

Joined: May 02, 2000
Posts: 69
Thanks sean i get the problem it was the next connection jps which has global data declated. Yet one more issue has cropped up
if i have two methods which do not have any data which is related to the doGet() and want to return a value which is boolean. The result of the operation inside the method is also required which will be used inside the doGet(), since no global data is declared how does the doGet() get the desired data from the operation, since "String" is pass by value, i had to use String array declated inside the doGet() as use pass by refrence.
class MyServlet
{
public void doGet()
{
// flow of operation but just check the lvs_qty
}
void one()
{
// calcuated leavs qty used by two()
two(lvs_qty)
}
boolean void two(lvs_qty)
{
// some operation performed on leaves qty
// required this value in doGet()
if lvs > 0
return true
else
return false
}
}
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I'd find some way to pass the data to the methods. Either a map or the request object itself. It's pretty much the only way.(well there are a couple of othe tricks but this is the easiest and cleanest). Or you could make a utility class that you can instantiate within the doGet() method and have that do the processing. This way, the object and its data are only within the scope of that particular request. (I think that's how it works).
Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use diffrent servlet values (how to unload a servlet)