• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Multiple clients

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
we have developed a small application using servlets and jsp. our application works fine when a single client tries to use it but when more than one client tries to access the same application, two exceptions are thrown
1.Protocol violation
2.Invalid arguments in column
i could not understand why this is happening can anyone please explain what could be the problem? and what should be done to enable multiple clients to access the application at the same time.

Thank you
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We would need a lot more information.
You shouldn't need to do anything special in order to support multiple users.
Can you post the stack trace and the code for the servlet that's blowing up?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first things to check is whether your servlets/controllers (and the services and POJO used by them) are thread-safe *and* stateless. Without looking at your code, a problem that only occurs during concurrent accesses would suggest something like this...
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a very easy mistake to use member variables in a servlet which is not thread safe. You can try to turn all those into local variables and parameters in the doWhatever methods and the methods they call. That can be a bit ugly. Or you can take all the code out of doPost or doGet and put it into another object which you make thread safe.

Worker can safely use member variables because we make a new instance for every request. This defeats the container's effort to reduce object creation and GC by reusing a single servlet instance, but as long as the Worker is cheap to create it's not too bad.
[ January 25, 2006: Message edited by: Stan James ]
 
Shanthi Murugeson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
this is the stack trace i am getting...


java.sql.SQLException: Protocol violation
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:594)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1983)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:1250)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:295)
at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.next(Unknown Source)
at DatabaseServlet.doGet(DatabaseServlet.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:635
0)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
java.sql.SQLException: Io exception: invalid arguments in call
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
at oracle.jdbc.driver.OracleStatement.freeLine(OracleStatement.java:6502)
at oracle.jdbc.driver.OracleConnection.needLine(OracleConnection.java:2415)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:291)
at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.next(Unknown Source)
at DatabaseServlet.doGet(DatabaseServlet.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:635
0)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

and the line corresponding to "DatabaseServlet.doGet(DatabaseServlet.java:97)" is
rs = dmd.getColumns(null,null,tablename,null);
where rs is the resultset, dmd is the object of databasemetadata and tablename is the name obtained from the jsp page.

please help me..
thank you..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you declared any of the database variables (connection, resultest, etc..) as instance varaibles?
 
Shanthi Murugeson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i have declared my connection variable as an instance variable.
infact all the variables in the program are instance variables.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shanthi Murugeson:
yes, i have declared my connection variable as an instance variable.
infact all the variables in the program are instance variables.



The connection object is not thread safe. Create a new instance (or get from connection pool) for each request.
 
Shanthi Murugeson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my code..



[ February 06, 2006: Message edited by: Shanthi Murugeson ]
[EDIT - code tage added by Dave]
[ February 06, 2006: Message edited by: David O'Meara ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, your SErvlet is not thread-safe. Servlet containers only create a single instance of a Servlet and run multiple requests through it. If you have instance variables like you have above, each of the threads can change it to a different value while another thread is using the old value, hence not thread safe.

Remove all of the instance variables for a start
 
Shanthi Murugeson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thank everyone for your replies..

It is working fine now.. I just need a small guidance. Can you please tell me where should we establish our connection and release all the connections. Previously we had all these in the init() and destroy() method.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can implements javax.servlet.SingleThreadModel to mark your servlet to use single threading model. This is not recommended and performance impact is huge when service method execution is long.

You can open and close the connection in the service method if the connection is managed by a connection pool. or else you can just leave it open to save creation time later.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eddy Lee Sin Ti:
You can implements javax.servlet.SingleThreadModel to mark your servlet to use single threading model. This is not recommended and performance impact is huge when service method execution is long.

.



SingleThreadModel is deprecated. So avoid that API and also it not really useful.

You can open and close the connection in the service method if the connection is managed by a connection pool. or else you can just leave it open to save creation time later


What do you mean by keeping it open ? Are you suggesting to use instance varibale for connection objetc. It is not thread safe.Connection objects should be closed when done using it whether one uses Connection pooling or not.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic