• 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

keep connection

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi how do you set so that you can keep the connection alive in a servlet ? I want to always have a doGet to send response to my client.
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ruslan,
If you want your connection to be alive for all the requests served by the servlet, you would need to initialize the Connection in the servlet init() method.
Although this technique would solve your problem, the threading issue would still be there.Hence, you would need to either use the synchronized block for accessing the Connection Object.
You may encounter performance problems , particularly,if your web-traffic is quite high.The best work-around for this would be "Connection Pooling", if the number of users are too many and unpredictable.
Hope this helps
Regards,

------------------
Sandeep Desai
vgdesai@vsnl.com

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ivanov,
By 'connection' do you mean database connection? When I first read your post, I thought you want keep the connection made by the browser to be alive all the time.
I don't remember exactly. There is a 'keep-alive' = true HTTP header setting available.
regds
maha anna
 
Ruslan Ivanov
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello , by connection i mean a connection to a requested servlet not a database. Maha could it be setHead("Connection","keep-alive") ? I can't find anything on it.
Here is how i solve this current problem. I spawn a thread which reads data off the Inputstream from the socket. I have a synchronized block where i issue a wait method to wait so i won't leave the doGet() method. If my thread finishes execution i then notify to leave the doGet method this works fine. But i think it screws up some part of my servlet application. I am making a chat servlet where this servlet just reads the data from the socket. But when i connect another user in the other instance of the browser this one stops recieving messages from my server only the one that is in the other browser windows continues recieving. Could this be the problem with my approach ? Or is it caused that i am running both clients that access my servlet though same machine which is now trying to fight which one will recieve a respond from the server ? What i asked does it make sence ? if not i'll try to rephrase it. thanks.
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ruslan,
Am sorry for interpreting your message incorrectly.I thought, you required information on DB connection.
To maintain a persistent connection with the client, as you have rightly mentioned, you would need to set an appropriate header.
I am quoting a paragraph, from Jason Hunter's book - Servlet Programming, where he discusses about HTTP Response Headers.It is available on Page 146, Table 5-2, in his book.


Connection Used to indicate whether the server is willing to maintain an open(persistent) connection to the client.If so,its value is set to keep-alive.If not,its value is set to close.Most web servers handle this header on behalf of their servlets, automatically setting its value to keep-alive when a servlet sets its Content-Length header.


Hope this helps,
Regards,


------------------
Sandeep Desai
vgdesai@vsnl.com

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  5. [This message has been edited by Desai Sandeep (edited April 10, 2001).]
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic