• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

use diffrent servlet values (how to unload a servlet)

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic