Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Config Tomcat -> Run Multiple Thread of Servlet ** (Problem Solved - Initialization error in code) *

 
Daniel Rodriguez Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody.

I am developing an applet which connects with a servlet deployed in Tomcat. The Servlet create a "new context", we can call it, when it inits, but I need that every time that an applet connects itself against servlet, Tomcat start a new thread of servlet.

Can this be configured in the config files of Tomcat?... May I create a Servlet which implements "Runnable"?..

Thank you.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that the applet connects with typical HTTP request/response architecture you don't have to do a thing. Tomcat automatically handles assigning a unique Thread to a request.

You could use the built-in HttpSession mechanism to track each applet instance or create your own identified by a unique cookie value.

Bill

 
Daniel Rodriguez Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I have the next problem.. When I run the servlet first time, it execute a Model method.. in the model runs the SQL query and returns the result... But when I request the same petition second time, the Model returns the previous response...ie as if it returned from a cache memory (I guess the Tomcat)

Example..

First Time ---- > Petition to Servlet --- > Servlet request Model ---> Time 5s (example) --> Model response right answer.
Second Time --> Petition to Servlet -- > Servlet request Model --> Time 0,5s ---> Model response first time answer

It seems like a cache memory (Tomcat maybe).. or something like that..

On the other hand... may I use Sessions with Applet?, or use it withing php or jsp page?

Thank you.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caching might be a good guess, but blame it on the browser you are using, not on Tomcat. Does every request to that servlet use the same URL? Does the servlet send headers telling the browser not to cache?
 
Daniel Rodriguez Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the applet uses the same URL to request to servlet..

Here I paste the method which returns my HttpURLConnection (Used in Applet).



As you can see, I use the method "setUseCaches(false)"..

Here I paste the doPost method of the servlet.
As you can see, there is a line with "fingerprindSDK = new MatchingContext()".. I thought that "context" is created only once, because first time, the servlet takes 5 seconds (example) to execute the doPost method, while second time it takes 0,5s..
I tried to use the "fingerprintSDK.destroy()", to every time it execute doPost method, it destroyed the "context", but It seems like it dont work properly.



Browser problem?, Config problem?.... Code problem maybe?..
What do you think?

Thank you
 
Daniel Rodriguez Hernandez
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem Solved!..

There was a initialization problem in the Model... the var "userIdentify" at the begining was "false", but in second time of execution, was "true" and it didn't go back to "false"... Initialitation problem...

Thank you for your replys... Change the topic if you can
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic