File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Config Tomcat -> Run Multiple Thread of Servlet ** (Problem Solved - Initialization error in code) * Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Config Tomcat -> Run Multiple Thread of Servlet ** (Problem Solved - Initialization error in code) *" Watch "Config Tomcat -> Run Multiple Thread of Servlet ** (Problem Solved - Initialization error in code) *" New topic
Author

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

Daniel Rodriguez Hernandez
Greenhorn

Joined: Nov 26, 2009
Posts: 13
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Nov 26, 2009
Posts: 13
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Nov 26, 2009
Posts: 13
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

Joined: Nov 26, 2009
Posts: 13
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
 
jQuery in Action, 2nd edition
 
subject: Config Tomcat -> Run Multiple Thread of Servlet ** (Problem Solved - Initialization error in code) *
 
Similar Threads
Connecting an applet to my struts data
How to best handle this situation
Connecting to a remote servlet from an unsigned applet
Quartz: How to avoid applet alerts???
Redirect from servlet to html (or php) web?